Hi, trying to switch from Ktor (client) 3.3.x to e...
# serialization
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
Which version of xmlutil (I guess) do you use?
w
0.91.2 (as sourced by ktor-serialization-kotlinx-xml:3.3.0)
What used to be serialized as
Copy code
<ebicsDummyRequest xmlns="urn:org:ebics:H005" Version="H005">
    <header>headerValue1</header>
</ebicsDummyRequest>
now turns into
Copy code
<ebicsDummyRequest xmlns="urn:org:ebics:H005" xmlns:n1="urn:org:ebics:H005" n1:Version="H005">
    <n1:header>headerValue1</n1:header>
</ebicsDummyRequest>
p
@Werner Guttmann I'm not often on Slack (too much day-to-day academic work is contraindicated of any IM platform), but if you can indicate what is going on (or file an issue on github.com/pdvrieze/xmlutil/issues) I wil l have a look. However, looking at the output, the issue appears to be related to the "fixed" handling of attribute namespaces. Per the XML specification attributes without prefix are always assigned to the null/empty namespace, and never to the default namespace. I suspect that your attribute has the namespace explicitly declared on it, which causes
Version
it to be placed in the
ebics:H005
namespace with the
n1
prefix. The fix in this case is to set the namespace to empty. If you left it empty/unset and this occurs that is a bug.
Please note that the old behaviour to consider attributes without a prefix to belong to the default namespace is incorrect. Convention is to use null-prefix attributes when the attribute is to be used in a tag that is defined in the same schema/document definition. Namespaced attributes are generally to be used on other tags that allow arbitrary attributes (e.g.
xml:lang
is a standard attribute to specify the language for the content of the tag it is applied to). As such, don't specify the namespace for "normal" attributes and the library will do the right thing.