Skip to content

illegal position for attribute when @Contextual LocalDate (Attribute) is declared after an Enum (Element) #364

@hfhbd

Description

@hfhbd

The following class fails with this error:

@Test
fun bug() {
  XML.v1.encodeToString(
    Bug.serializer(),
    Bug(BugEnum.ABC, LocalDate.fromEpochDays(0))
  )
}

@Serializable
data class Bug(
  val enum: BugEnum,
  @Contextual val date: LocalDate,
)

enum class BugEnum {
  ABC,
}
illegal position for attribute
java.lang.IllegalStateException: illegal position for attribute
	at nl.adaptivity.xmlutil.core.KtXmlWriter.attribute(KtXmlWriter.kt:574)
	at nl.adaptivity.xmlutil.XmlWriterUtil__XmlWriterKt.writeAttribute(XmlWriter.kt:507)
	at nl.adaptivity.xmlutil.XmlWriterUtil.writeAttribute(Unknown Source)
	at nl.adaptivity.xmlutil.serialization.XmlEncoderBase.smartWriteAttribute(XMLEncoder.kt:975)
	at nl.adaptivity.xmlutil.serialization.XmlEncoderBase.access$smartWriteAttribute(XMLEncoder.kt:33)
	at nl.adaptivity.xmlutil.serialization.XmlEncoderBase$XmlEncoder.encodeString(XMLEncoder.kt:139)
	at kotlinx.datetime.serializers.LocalDateSerializer.serialize(LocalDateSerializers.kt:124)

Versions:
Kotlin: 2.3.21
xmlutil: 1.0.0-rc2

Metadata

Metadata

Assignees

No one assigned

    Labels

    in devThe issue is fixed/implemented in the dev branch

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions