Skip to content

Can't deserialise an empty tag into an instance with no fields #209

Closed
@jlous

Description

@jlous

As noted in #89:

  • jackson deserializes <x></x> and <x/> for leaf-nodes as NULL..
  • JAXB deserializes <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

   <myObject>
       <someStructuredData>...</someStructuredData>
       <flag1/>    
       <flag3/>
   </myObject>

This maps naturally to fields that can be null or populated with objects that are dumb, but typed:

   class myObject{
       SomeStructuredData someStructuredData;
       Flag1 flag1;
       Flag2 flag2;
       Flag3 flag3;
   }

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions