Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty QName deserialized as null #4450

Closed
1 task done
winfriedgerlach opened this issue Mar 25, 2024 · 5 comments
Closed
1 task done

Empty QName deserialized as null #4450

winfriedgerlach opened this issue Mar 25, 2024 · 5 comments
Labels
2.17 Issues planned at earliest for 2.17

Comments

@winfriedgerlach
Copy link

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

@winfriedgerlach winfriedgerlach added the to-evaluate Issue that has been received but not yet evaluated label Mar 25, 2024
@cowtowncoder
Copy link
Member

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.

@winfriedgerlach
Copy link
Author

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

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

@cowtowncoder
Copy link
Member

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.

@cowtowncoder cowtowncoder added 2.18 2.17 Issues planned at earliest for 2.17 and removed to-evaluate Issue that has been received but not yet evaluated 2.18 labels Apr 1, 2024
@cowtowncoder cowtowncoder changed the title Empty QName deserialized as "null" Empty QName deserialized as null Apr 6, 2024
@winne42
Copy link

winne42 commented Sep 5, 2024

thanks again, @cowtowncoder , we are using your fixed version now :-)

@cowtowncoder
Copy link
Member

@winne42 Great! Thank you for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.17 Issues planned at earliest for 2.17
Projects
None yet
Development

No branches or pull requests

3 participants