-
Hello. First, thanks for this awesome library! I'm getting stuck on something. The simplest version of it is something I can't wrap my head around. my understanding of XML is pretty shallow, so i thought after spending 4 hours trying to figure this out i'd ask the experts. here's what i've done so far:
Here is the simplest picture of what i'm trying to do. Say i have some xml like:
I am parsing this using
the tricky part is the the serializer decodes XML strings just fine meaning it will parse the xml string to data classes without an issue. however, it does not encodeToString as I would expect. When i encode it to a string I get the following:
This isn't valid for the use case i have. The
so it seems i can only get ONE direction to work at a time. Please let me know what I'm doing wrong here. Thanks again!!!! UPDATE
i get
in fact, every attempt to decode throws that error no matter what i use for the annotation 😭 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
First of all (for the updated bit), you should probably use For xml:id, you will need to specify the proper namespace. When serializing, the prefix is used only on an advisory level (because prefixes are not semantically relevant, and multiple prefixes for the same namespace create unneeded noise). The value you want is: note while the prefix xml is forced to that namespace (as the standards specify), the decoder does not do this. |
Beta Was this translation helpful? Give feedback.
First of all (for the updated bit), you should probably use
@XmlSerialName
that allows specifying names. The format uses namespaces, "assumes" that there are no special characters in the serial name. You can create your own policy to try to interpret it differently (there is no single way to transform serial names into qnames).For xml:id, you will need to specify the proper namespace. When serializing, the prefix is used only on an advisory level (because prefixes are not semantically relevant, and multiple prefixes for the same namespace create unneeded noise). The value you want is:
@XmlSerialName("id", "http://www.w3.org/XML/1998/namespace", "xml")
.note while the prefix xml is force…