-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
XML Empty tag to Empty string in the object during xml deserialization #162
Comments
Yes I can reproduce this. It is a tricky problem to solve but I added a failing unit test so that hopefully it may be resolved in future. In the meantime a work-around would be to add explicit |
I have some ideas as to how this could be implemented; but actual fix will need to wait until 2.8 unfortunately, as some API changes will be needed. |
I'm also facing what I think is the same issue. State A : Both A and B are defined in XSD as being 'xsd:string' with max length 0 characters. 'Thing' is a complextype, defined as being xsd:choice between element A or element B. They are intended to have no content; it is purely the presence or absence of the empty element which declares which state we are in. Sadly I don't have control over the interface to be able to change the logic. I have to live with this XML interface. In Java, the POJO generated from XSD has String fields 'a' and 'b'. If I serialize from POJO to XML I have no problem, but the trouble comes when I try to deserialize again. If I deserialize So you see, I'm unable to detect WHICH empty element was present, which leaves me unable to know which state it was in. If I could submit some content inside the A / B, even just a space character, then it would deserialize properly. But I can't validly submit content inside the A / B element, because that would not be acceptable according to the XSD (max length 0 characters). I see this as a fault, really, because dataformat-xml cannot read back in the xml which it itself has outputted. If I serialize a Thing from POJO to XML string and then deserialize back to POJO again, I don't get back in the same object I wrote out. (Quoting the readme page: "What should be guaranteed is that any XML written using this module must be readable using module as well") |
@RobinAllen This is indeed problematic, but consider that without mandating use of XML Schema's nillable, there really is nothing to definitely differentiate empty String from Anyway, I do hope that with 2.8 (to be worked on next now that 2.7.0 is ready to release) we can at least ensure that empty element, for |
Hello what is the status of this situation? I am working with Thanks |
@manueljordan If there is progress, there will be update here. I have not worked on this, and am unlikely to have much time in near future. |
@cowtowncoder thanks by the quick reply. I understand. The important is it was reported. Yes, take your time, I know you are busy. Meanwhile I have turned around this situation in other way. |
Eagerly awaiting this! Would a pull-request make any difference in ETA in an official release? |
Any idea when the PR might be merged if approved? |
What is needed to approve the PR? |
Yeah, what is stopping this? |
@cowtowncoder |
This is a pretty painful issue to run into, but after a lot of not-so-fun experimentation I came up with two different workarounds that I think should handle most use-cases. You can check them out here |
Fix for #162 (XML Empty tag to Empty string)
Quick note: related to #209, Jackson 2.9 SHOULD allow use of:
to basically coerce FasterXML/jackson-databind#1402 I will test that this works, and if so, mark this as closed. |
Ok. Hmmh. So, good and bad news. Good news: woth empty tags, works as expected. Bad news: open+start, without even intervening space (so simple |
So. Works as suggested with empty tag, in 2.9. And with In 3.0.0 will further work the same way for "split" empty tag (start+end). |
Note: some of the fixes to |
Is there any fix for this which is available? |
I am using jackson-dataformat-xml:2.6.2
If an empty tag is available in the xml and the respective field in the object is a string, it would be nice to have jackson populate the field with empty string rather than with null value.
Ex:
xml:
mapper creation:
I would expect
name.getLast().equals("") to return true but name.getLast() ends up being null.
Any help would be appreciated.
The text was updated successfully, but these errors were encountered: