1

I'm using JAXB to serialize objects to XML. I want to exclude elements with default values in my response. While serializing objects to JSON i have used JsonSerialize.Inclusion.NON_DEFAULT in the ObjectMapper configuration to exclude default values.

SerializationConfig sc = objectMapper.getSerializationConfig()
       .withSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT);
objectMapper.setSerializationConfig(sc);

I want same behavior for XML response also. How can i do this?

  • 1
    Use the boxed types instead of primitives. JAXB should exclude nulls by default. And change Jackson to exclude nulls instead of defaults. Not much else you can do. I don't think JAXB is as smart as you need it to be to get your desired behavior. – Paul Samsotha Jul 05 '16 at 09:44

0 Answers0