ams ams - 2 years ago 156
Java Question

How to tell Jackson to ignore a field during serialization if its value is null?

How can Jackson be configured to ignore a field value during serialization if that field's value is null.

For example:

public class SomeClass {
// what jackson annotation causes jackson to skip over this value if it is null but will
// serialize it otherwise
private String someValue;

Answer Source

To suppress serializing properties with null values, you can configure the ObjectMapper directly, or make use of the @JsonInclude annotation:



class Foo
  String bar;

A more complete example is available in my answer to How to prevent null values inside a Map and null fields inside a bean from getting serialized through Jackson.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download