Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

JaxbAnnotationIntrospector does not honor JsonInclude.Include.NON_EMPTY set on ObjectMapper #39

@jdmichal

Description

@jdmichal

I am configuring a Jackson JSON provider with a JAX-RS application's getSingletons() method. Note setting of NON_EMPTY:

final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JaxbAnnotationModule());
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
final JacksonJaxbJsonProvider jsonProvider = new JacksonJaxbJsonProvider(
    objectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS);

Let's also define a piece of dummy data:

@XmlType
public class Data {
    private final List<Object> stuff = new java.util.ArrayList<Object>();

    @XmlElement
    public List<Object> getStuff() {
        return this.stuff;
    }
}

Given that stuff is empty, I would expect this to output an empty object. However, it instead outputs:

{
    "stuff": [ ]
}

I have isolated this behavior to JaxbAnnotationIntrospector.findSerializationInclusion. (This is the 2.4.4 version, but this function is currently unmodified on master.) This function receives the default value of NON_EMPTY, but will return NON_NULL as long as the XmlElement annotation is present.

Given that this behavior is unexpected given the configuration, and also conflicts with the JAXB behavior of not serializing the list, I believe this function should return NON_EMPTY instead of NON_NULL if:

  • XmlElementWrapper is not present. (JAXB would output an empty element with the wrapper's name.)
  • XmlElement is present.
  • The given default is NON_EMPTY.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions