Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value class causes wrong order during serialization #195

Open
hfhbd opened this issue Feb 8, 2024 · 3 comments
Open

Value class causes wrong order during serialization #195

hfhbd opened this issue Feb 8, 2024 · 3 comments
Labels
indev The issue is fixed/implemented in the dev branch

Comments

@hfhbd
Copy link

hfhbd commented Feb 8, 2024

Hey,
I expect the order of the encoded elements would be the same as the order of the declaration:

@Serializable
@XmlSerialName("Foo")
data class Foo(
  @XmlElement
  @XmlSerialName("ServiceName")
  val serviceName: String? = null,

  @XmlElement
  @XmlSerialName("SendingSystem")
  val sendingSystem: Code? = null,
) {
  @JvmInline
  @Serializable
  @XmlSerialName("Code")
  value class Code(
    val `value`: String,
  )
}
assertEquals(
  expected = "<Foo><ServiceName>a</ServiceName><SendingSystem>b</SendingSystem></Foo>",
  actual = XML.encodeToString(foo) // <Foo><SendingSystem>b</SendingSystem><ServiceName>a</ServiceName></Foo>
)

Kotlin 1.9.22
Kotlinx serialization core: 1.6.2
XmlUtil: 0.86.3

There is a workaround though using a regular data class:

@Serializable
@XmlSerialName("Foo")
data class Foo2(
  @XmlElement
  @XmlSerialName("ServiceName")
  val serviceName: String? = null,

  @XmlElement
  @XmlSerialName("SendingSystem")
  val sendingSystem: Code? = null,
) {
  @Serializable
  @XmlSerialName("Code")
  data class Code(
    @XmlValue
    val `value`: String,
  )
}
@pdvrieze
Copy link
Owner

pdvrieze commented Feb 9, 2024

I had a look. This was indeed a problem with handling reordering in the "correct way" - reordering must be delayed for the actual inline value (a special case), but then the actual child wasn't reordered properly.

@pdvrieze pdvrieze added the indev The issue is fixed/implemented in the dev branch label Feb 12, 2024
@pdvrieze
Copy link
Owner

The fix should be available in the snapshots.

@hfhbd
Copy link
Author

hfhbd commented Feb 13, 2024

Thanks, will try it out next days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
indev The issue is fixed/implemented in the dev branch
Projects
None yet
Development

No branches or pull requests

2 participants