-
-
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
Deserialization of an empty list (with empty XML tag) results in null
#124
Comments
Just faced the same issue. Are there any plans to make this behavior configurable? |
At first I'd need to understand what the problem is: most likely it is due to convoluted way XML stream is read, to try to determine whether an element would be considered equivalent to JSON Object or Array. Another thing to try to is to see if 2.5.0 makes any difference; there was at least one fix related to List/array handling. |
Just tried 2.5.0: @Test
public void canDeserializeEmptyCollection() throws IOException {
String xml =
"<PersonList>" +
"<people />" +
"</PersonList>";
XmlMapper xmlMapper = new XmlMapper();
PersonList personList = xmlMapper.readValue(xml, PersonList.class);
assertNotNull(personList.people); // <--- HERE
assertEquals(0, personList.people.size());
}
public static class PersonList {
@JacksonXmlElementWrapper(localName = "people")
@JacksonXmlProperty(localName = "person")
public List<Person> people;
}
public static class Person {
public String name;
}
|
Thank you for verifying this. So, it is a bug, not an intentional deviation from JSON handling. |
any new on this, still the same issue in the latest jackson release... |
Just verified with 2.6.3 - still the same... |
Any update on the same ? |
No news here. |
Just ran into this problem myself...If you reverse the annotations it seems to work without issue:
|
null
Yes, I can reproduce this now. Whether empty element is expressed as |
Just curious if there is any ETA on a fix for this? Thanks. |
My workaround in 2.8.9 was a readResolve method that checks if any of the collections in the class were null and respectively created a new collection. |
Any solution to this? I see the same problem. I upgraded from 2.1.1 to 2.6.7. 2.1.1 was working. upgrade broke the tests while deserializing empty xml element into a array list property |
Still suffering with this bug in 2.8.10. Any ETA? Edit: Thought this was closed, but it was the related bugs. Still waiting for a fix for this bug. |
We also encountered this problem in our project. While trying to fix this i noticed that there is a feature FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL which is enabled by default. I tried to disable it but it did not make any difference in the above testcase.
Is this feature related to this problem? How can we make it work? |
Still this same issue in 2.10.0. Maybe someday... |
This might be fixed in 2.10.2, see #378 |
@henrik242 Unfortunately that is bit different problem. However! There is actually a way to make it work by using (relatively) new "config overrides" with null-handling override. Specifically, adding this:
will then convert logical |
Fixed for 2.12.0 |
FasterXML/jackson-module-kotlin#396 might be related to this (jackson 2.12.0-rc1 regression) |
null
null
@henrik242 If there is a remaining problem with this issue on 2.12.1, reproducible with just this module (there are some issues related to Kotlin module which gets trickier), could you please file a new issue with reproduction? |
@cowtowncoder I've only managed to reproduce it with the kotlin and xml module together. So I'll just stick with FasterXML/jackson-module-kotlin#396 :) |
XML serialization/deserialization of an empty array is not working consistently (unlike JSON) .
When I try to deserialize an empty list from xml I get a null list (but I except to get an empty list).
I don't have this problem with JSON.
Library version 2.4.3, jdk 8.0_25
Here is my example
The text was updated successfully, but these errors were encountered: