-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Can't deserialise an empty tag into an instance with no fields #209
Comments
Note that explicit I agree in that handling of empty values is not optimal, but haven't figured a good way to handle it better. |
Just encountered this issue my self. The XML I'm parsing uses a child tag to define the type of the object. <ModelVariables>
<ScalarVariable name="h" valueReference="0" description="height, used as state"
causality="local" variability="continuous" initial="exact">
<Real start="1"/>
</ScalarVariable>
<ScalarVariable name="der(h)" valueReference="1" description="velocity of ball"
causality="local" variability="continuous" initial="calculated">
<Real />
</ModelVariables> From the above XML, the first list element gets serialized to a RealVariable because it contains the (non-empty) Real tag. The second case breaks the application because the tag is empty -> the field that decides the object type is set to null! |
Jackson 2.9 added one new feature for https://medium.com/@cowtowncoder/jackson-2-9-features-b2a19029e9ff (see "Null replacement/error/skipping (on deserialization)") which is RFE FasterXML/jackson-databind#1402 wherein annotating property as:
should result in Problem otherwise is that due to separate of streaming parser, databinding, lower level must decide in how to expose value, and as things are there is not enough information to be able to expose it either as I will add tests in XML module to ensure that this approach works (or, if not, that it needs to be fixed). |
One other thing: it is also possible to configure null-handling for type via
(examples can be found from test cases under I hope this helps. |
@JsonSetter(nulls=Nulls.AS_EMPTY) did the trick for me. Now I can replace JAXB with Jackson :) |
@markaren yay! |
As noted in #89:
<x></x>
and<x/>
for leaf-nodes as NULL..<x></x>
or<x/>
for leaf-nodes not as NULL-values but provides default-values (an integer will be 0 by default).This is a big problem for me. I need to deserialize a third-party schema which represents some state using the presence of a tag, in some cases with no children or attributes
This maps naturally to fields that can be null or populated with objects that are dumb, but typed:
After deserializing the example above I want flags 1 and 3 to be populated, and flag 2 to be null.
But I can find no way to get Jackson-xml to deserialise empty tags to anything but null.
Is it truly not supported, or am I just missing something? Discerning meaningfully between missing and empty tags is a perfectly valid use of xml, and should be supported in some way or other.
The text was updated successfully, but these errors were encountered: