Skip to content

Serialization of "JacksonXmlElementWrapper"-annotated List with NULL-Value #103

@5kilodope

Description

@5kilodope

I have defined a List of Objects in a POJO:

public class Order  {

  @JacksonXmlElementWrapper(localName = "line_items")
  @JacksonXmlProperty(localName = "line_item")  
  private List<LineItem> line_items = null;  

}

Normally this Element will be serialized like this if it is not null (this works as expected and is ok):

<order> 
  <line_items>
    <line_item>...</line_item>
  </line_items>
</order>

But if the List is provided as null it will be serialized like this (tested with Jackson 2.3.1):

<order> 
      <line_item/>
</order>

But correct would be:

<order> 
      <line_items/>
</order>

I also found a hint in the comments of the jackson-code :-)
See XMLBeanPropertyWriter:

        /* Hmmh. Does the default null serialization work ok here? For now let's assume
         * it does; can change later if not.
         */
        if (value == null) {
            if (_nullSerializer != null) {
                jgen.writeFieldName(_name);
                _nullSerializer.serialize(null, jgen, prov);
            }
            return;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions