pdvrieze / xmlutil

XML Serialization library for Kotlin
https://pdvrieze.github.io/xmlutil/
Apache License 2.0
363 stars 30 forks source link

IndexOutOfBoundsException: There are no children #173

Closed wbervoets closed 10 months ago

wbervoets commented 11 months ago

I get

java.lang.IndexOutOfBoundsException: There are no children
at nl.adaptivity.xmlutil.serialization.structure.XmlDescriptor.getElementDescriptor(XmlDescriptor.kt:151)
at nl.adaptivity.xmlutil.serialization.XML.collectNamespaces$collect$5(XML.kt:293)
at nl.adaptivity.xmlutil.serialization.XML.collectNamespaces$collect$5(XML.kt:303)
at nl.adaptivity.xmlutil.serialization.XML.collectNamespaces(XML.kt:311)
at nl.adaptivity.xmlutil.serialization.XML.encodeToWriter(XML.kt:216)
at nl.adaptivity.xmlutil.serialization.XML.encodeToWriter(XML.kt:172)
at nl.adaptivity.xmlutil.serialization.XML.encodeToString(XML.kt:117)
at nl.adaptivity.xmlutil.serialization.XML.encodeToString(XML.kt:104)

when enabling isCollectingNSAttributes. Any idea's?

    public open fun getElementDescriptor(index: Int): XmlDescriptor {
        throw IndexOutOfBoundsException("There are no children")
    }

I think it fails due to my xml elements or attributes being an enum class. Is that possible?

pdvrieze commented 11 months ago

That is possible. I will investigate.

pdvrieze commented 11 months ago

I've had a look. It was indeed an enum problem. Enums are treated as primitives (string values of their names), but there was an inconsistency in handling of child descriptors. This should be fixed in the snapshot (it should be available in about 20 minutes).

wbervoets commented 10 months ago

Thanks for the quick fix. I've just returned from holiday and can confirm that 0.86.2-SNAPSHOT is working fine