FasterXML / jackson-dataformat-xml

Extension for Jackson JSON processor that adds support for serializing POJOs as XML (and deserializing from XML) as an alternative to JSON
Apache License 2.0
567 stars 221 forks source link

QName Deserializer #543

Open vitorpamplona opened 2 years ago

vitorpamplona commented 2 years ago

QName is a special case of an XML Deserializer. This PR parses the contents of the QName and assigns the correct namespace from the XML stack. This mimics the behavior of JAXB parsers.

An XML like this:

<parent xmlns:t="urn:example:types:r1">
    <level1 name="t:DateTime" />"
</parent>";

Should automatically generate a parent.level1.name as QName("urn:example:types:r1", "DateTime", "t")

cowtowncoder commented 2 years ago

Ok, first of all: thank you for contributing this patch! I can see what it is attempting to do and that makes sense.

Unfortunately I am not sure this can be implemented in robust manner: the main problem being that there is no guarantee that

  1. There is a Stax parser associated with content -- in particular when buffering (using TokenBuffer) is used (most commonly when @JsonCreator annotated constructor used)
  2. Parser itself may not point to actual XML content element (in case of textual content it's probably pointing to closing element, in case of elements)

latter might not be a huge issue as long as namespace resolution context is still available, but former is problematic. I guess one could make code check accessibility and avoid lookup if parser not available. But that would be hugely confusing since it "sometimes works, sometimes not" (with no obvious signs to user).