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

ACCEPT_EMPTY_STRING_AS_NULL_OBJECT not honored in xml module for attributes #25

Closed
mortenoh opened this issue Apr 23, 2012 · 7 comments
Closed
Milestone

Comments

@mortenoh
Copy link

I'm having some issues with the treatment of empty strings in the XML module.

Say I have this:

class A {
 @JacksonXmlProperty( isAttribute = true )
 private String stringA;
 private String stringB;
}

A a = new A();
a.setStringA("");
a.setStringB("");

In JSON this would give me:

{ "stringA": "", "stringB": ""}

In XML this gives me:

<A stringA="">
 <stringB />
</A>

Which means that the attribute is treated correctly (as according to
the defaults), but for the element, it shows up as null. And is
therefore deserialized back as a null string.

@cowtowncoder
Copy link
Member

Hmmh. I don't quite follow: in XML is equivalent to ; there is no semantic difference.
I am also not sure iff ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is relevant here, as it is just for deserialization (reading JSON/XML as POJO)...

So what is the problem, and how would you expect things to work instead?

@mortenoh
Copy link
Author

Hi

I'm sorry I dont have access to my test project right now. But if I remember correctly, the issue was that, given the code:

class A {
 @JacksonXmlProperty( isAttribute = true )
 private String stringA = ""
 private String stringB = ""
}

This would give in XML (which I agree is correct):

<A stringA="">
 <stringB />
</A>

But, when deserialized, it would give me:

class A {
 @JacksonXmlProperty( isAttribute = true )
 private String stringA = ""
 private String stringB = null;
}

Hope this makes it a bit more clear. If you need more information, I will try and find my little test project for this.

@cowtowncoder
Copy link
Member

Ah! Yes, this explains it better. Thank you -- unit tests are always appreciated, but I think I now understand the issue and can work on it.

@cowtowncoder
Copy link
Member

Hmmh. ACCEPT_EMPTY_STRING_AS_NULL_OBJECT only states that empty String is a valid representation as null of any Object type, so behavior is not exactly incorrect.
But I can see it as sub-optimal. It probably works that way even without feature; I'll see if I can improve this as it would make sense to get empty String back. Chances are nothing gets set.

@cowtowncoder
Copy link
Member

Since this is an old issue I am not sure if it can be reproduced as is. There are newer related issues as well, so I will close this one in favor of newer ones.

@ewirch
Copy link

ewirch commented Apr 24, 2018

Can you reference "newer related issues"? This problem is still present for 2.9.5.

cowtowncoder added a commit that referenced this issue May 5, 2018
@cowtowncoder cowtowncoder added this to the 3.0.0 milestone May 5, 2018
@cowtowncoder
Copy link
Member

Turns out there was a unit test I had added earlier. Was able to fix but only for 3.0.0, unfortunately, not 2.9.

@cowtowncoder cowtowncoder changed the title ACCEPT_EMPTY_STRING_AS_NULL_OBJECT not honored in xml module ACCEPT_EMPTY_STRING_AS_NULL_OBJECT not honored in xml module for attributes May 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants