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();
  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 2010-04-01 21:36:39 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC