Skip to content

Parse children as Element or Text / CDATA #253

@AdrienDaily

Description

@AdrienDaily

Hello,

Using the version 0.86.3

I'm having trouble getting from a children either an Element or a Text / CDATA result.

<Extensions>
    <Extension source="mySource">
        <![CDATA[{"savedData":""}]]>
    </Extension>
    <Extension type="AdVerifications">
        <AdVerifications>
            <Verification vendor="Something">
                <JavaScriptResource apiFramework="omid" browserOptional="true">
                    <![CDATA[https://google.com/video.js]]>
                </JavaScriptResource>
                <VerificationParameters>
                    <![CDATA[{"key":"21649"}]]>
                </VerificationParameters>
            </Verification>
        </AdVerifications>
    </Extension>
</Extensions>
@Serializable
@SerialName("Extension")
data class ExtensionDto(
    val source: String? = null,
    val type: String? = null,
    @XmlValue
    var value: List<@Polymorphic Any> = listOf()
) {
    companion object {
        fun module() = SerializersModule {
            polymorphic(Any::class) {
                subclass(String::class)
                subclass(AdVerificationsDto::class)
            }
        }
    }
}

@Serializable
@SerialName("AdVerifications")
data class AdVerificationsDto(
    @XmlElement(true)
    var verifications: MutableList<VerificationDto>? = mutableListOf()
)

I'm not sure if it's the right way to handle it and I get this error:

java.lang.IllegalArgumentException: Polymorphic value has not been read for class null
                                    	at kotlinx.serialization.internal.AbstractPolymorphicSerializer.deserialize(AbstractPolymorphicSerializer.kt:67)
                                    	at nl.adaptivity.xmlutil.serialization.XmlDecoderBase$AnonymousListDecoder.decodeSerializableElement(XMLDecoder.kt:905)
                                    	at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:538)
                                    	at kotlinx.serialization.internal.CollectionLikeSerializer.readElement(CollectionSerializers.kt:80)
                                    	at kotlinx.serialization.internal.AbstractCollectionSerializer.readElement$default(CollectionSerializers.kt:51)
                                    	at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:36)
                                    	at nl.adaptivity.xmlutil.serialization.XmlDecoderBase$TagDecoder.decodeSerializableElement(XMLDecoder.kt:459)

Thanks a lot for your help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions