Jackson feature: prevent serialization of nulls, default values

As of Jackson 1.1, you can suppress serialization of properties that have either:

These is achieved by using one of 2 mechanisms:

So either:

  ObjectMapper mapper = new ObjectMapper();
  // Jackson 2.x OR
  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // no more null-valued properties
  // Jackson 1.x
  mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); // no more null-valued properties

or

  @JsonSerialize(include=JsonSerialize.Inclusion.NON_DEFAULT)
  public class MyBean {
    // ... only serialize properties with values other than what they default to
  }


Back to JacksonFeatures11


CategoryJackson

JacksonAnnotationSerializeNulls (last edited 2012-11-30 19:57:25 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC