pdvrieze / xmlutil

XML Serialization library for Kotlin

Home Page:https://pdvrieze.github.io/xmlutil/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java target does not contains trailing space

hfhbd opened this issue · comments

I have this multiplatform (jvm, macOS (arm/x64), linux(arm/x64)) test:

@Serializable
data class Out(
  val b: String,
  val c: Int,
)

@Test fun output() {
  assertEquals("""<Out b="b" c="42"/>""", XML.encodeToString(Out("b", 42)))
}

On JVM (temurin 21), the test pass, while on macOS/Linux the test returns """<Out b="b" c="42" />""" (with a trailing space).

(I am also okay with removing the space from the native targets.)

Version: 0.86.3

@hfhbd This is an issue that can't really be solved. The problem is that the library uses different output backends. You can use the generic one on all platforms, but there are 3 other backends: Java (using the stax api - it uses its own pluggable backends); Android (using the XMLPullParser), JS (using DOM).

There are two ways to make your tests work (see also the test suite of the library):

  • Have a normalization function (replace ' />' with '/>' etc.)
  • Use an xml aware comparison: The library uses an assertXmlEquals function. I'm not sure it is available externally, but I could publish it/open it up.

Thanks for the answer, I already thought so, so I chose the normalization function in my tests.