FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty QName deserialized as `null`

winfriedgerlach opened this issue · comments

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

When deserializing javax.xml.QNames, IMHO QName.valueOf() should always be used. Unfortunately, Jackson has a different code path when deserializing an empty string "": Instead of a QName instance with an empty local part, null is returned.

Version Information

2.16.1

Reproduction

<-- Any of the following

  1. Brief code sample/snippet: include here in preformatted/code section
  2. Longer example stored somewhere else (diff repo, snippet), add a link
  3. Textual explanation: include here
    -->
// happy case
var qname1 = new ObjectMapper().readValue("\"a\"", QName.class);
assert qname1 instanceof QName;
assert qname1.getLocalPart().equals("a");

// bug (IMHO)
var qname2 = new ObjectMapper().readValue("\"\"", QName.class);
assert qname2 instanceof QName; // false, qname2 is null
assert qname2.getLocalPart().isEmpty();

Expected behavior

No response

Additional context

No response

Quick question: is QName with empty local part legal? It would not be legal XML identifier but I guess as an Object maybe it is allowed.

Hello @cowtowncoder , according to the javax.xml.namespace.QName JavaDoc:

A local part of "" is allowed to preserve compatible behavior with QName 1.0

Ok, fair enough.

I'll try to follow up with this when I get a chance; or if you (or anyone else) wants to provide a PR (against 2.18 I think as it's behavioral change) would be happy to review and merge.