Hi, trying to switch from Ktor (client) 3.3.x to e...
# ktor
w
Hi, trying to switch from Ktor (client) 3.3.x to e.g. 3.5.0 in one of my projects, and after refreshing the Gradle build, any serialization to XML is broken with regards to how attributes are marshalled (additional namespaces being wrongly created) . Any idea where a description of this problem is to be found (as hopefully I am not the first one to run into this). Switching to any 3.x below 3.3 is not a problem, but any switch to 3.4 and above causes XML marshalling to fail.
h
It's a bug of xmlutil, just update the version
👍 1
w
Upgraded to 1.0.0rc3 ... Trying to serialize
Copy code
package domain

import kotlinx.serialization.Serializable
import nl.adaptivity.xmlutil.ExperimentalXmlUtilApi
import nl.adaptivity.xmlutil.serialization.XmlElement
import nl.adaptivity.xmlutil.serialization.XmlNamespaceDeclSpecs
import nl.adaptivity.xmlutil.serialization.XmlSerialName

@OptIn(ExperimentalXmlUtilApi::class)
@Serializable
@XmlSerialName("ebicsDummyRequest", "urn:org:ebics:H005")
@XmlNamespaceDeclSpecs("urn:org:ebics:H005")
data class EBICSDummyRequest(
    @XmlSerialName("header", "urn:org:ebics:H005")
    @XmlElement(true)
    val header: String,
    @XmlElement(false)
    @XmlSerialName("Version", "urn:org:ebics:H005")
    val version: String
)
results into
Copy code
<?xml version='1.1' ?>
<ebicsDummyRequest xmlns="urn:org:ebics:H005" xmlns:ns1="urn:org:ebics:H005" ns1:Version="H005">
    <ns1:header>headerValue1</ns1:header>
</ebicsDummyRequest>
rather than
Copy code
<ebicsDummyRequest xmlns="urn:org:ebics:H005" Version="H005">
    <header>headerValue1</header>
</ebicsDummyRequest>
h
You don't need both namespace declarations
Just use XmlSerialName
And you also don't need to repeat the namespace for each attribute
Copy code
package domain

import kotlinx.serialization.Serializable
import nl.adaptivity.xmlutil.ExperimentalXmlUtilApi
import nl.adaptivity.xmlutil.serialization.XmlElement
import nl.adaptivity.xmlutil.serialization.XmlNamespaceDeclSpecs
import nl.adaptivity.xmlutil.serialization.XmlSerialName

@OptIn(ExperimentalXmlUtilApi::class)
@Serializable
@XmlSerialName("ebicsDummyRequest", "urn:org:ebics:H005")
data class EBICSDummyRequest(
    @XmlSerialName("header")
    @XmlElement(true)
    val header: String,
    @XmlElement(false)
    @XmlSerialName("Version")
    val version: String
)
And you also don't need XmlElement(false)
Or XmlSerialName with the same name: header
w
@hfhbd Thanks for pointing out all those things .. but that redundancy, that has a reason doesn't explain why the XML being produced all of a sudden is broken. a) I have about 70 classes that represent a set of complex XML schemas b) marshalling to JSON and/or CBOR is a requirement as well
In other words, why make this redundancy a difference all of a sudden (in relation to a version change)
h
xmlutil is not stable yet and every software can have bugs.
w
That's understood ...