Handling XMLElement nillable like JAXB · Issue #89 · FasterXML/jackson-dataformat-xml (original) (raw)
I cant find any way to make Jackson serialize the typical "xsi:nil"-Attribute that is defacto standard to represent NULL-Values in XML? Please correct me if i see this wrong ;-)
In JAXB this can be done easily by annotating a java-variable with: @xmlelement(nillable=true)
see also: http://blog.bdoughan.com/2012/04/binding-to-json-xml-handling-null.html
can/should Jackson do this?
here also a compare of JAXB and Jackson.
- jackson serializes NULL-values per default as
- can be configured so NULL-values will not be serialized at all
- jackson deserializes missing elements as NULL
- jackson deserializes and for branch-nodes as NULL
- jackson deserializes and for leaf-nodes as NULL..
but as soon as attributes (z.b. xsi:nil) are on the leaf-node, jackson
seems to think its a branch-node instead and throws an exception
while mapping it to an pojo - JAXB does not serialize NULL-values per default
- If fields are annotated with @nillable, the field will be serialized as <x xsi:nil="true/>
- JAXB deserializes missing elements as NULL
- If fields are annotated with @nillable, will be deserialized as NULL
- JAXB deserializes or for branch-nodes by providing default-values for all contained
leaf-nodes. - JAXB deserializes or for leaf-nodes not as NULL-values but provides default-values (an integer will be 0 by default).
so it seems to me that the best way at the moment is not to serialize/deserialize NULL-values but just leave them out. The only bad thing about this is, that empty strings "" can not be represented...