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

mapper.setSerializationInclusion(Include.NON_NULL);

or:

@JsonInclude(Include.NON_NULL)
class Foo
{
  String bar;
}

Alternatively, you could use @JsonInclude in a getter so that the attribute would be shown if the value is not null.

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.

Answer from Programmer Bruce on Stack Overflow
Top answer
1 of 16
1374

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

mapper.setSerializationInclusion(Include.NON_NULL);

or:

@JsonInclude(Include.NON_NULL)
class Foo
{
  String bar;
}

Alternatively, you could use @JsonInclude in a getter so that the attribute would be shown if the value is not null.

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.

2 of 16
205

Just to expand on the other answers - if you need to control the omission of null values on a per-field basis, annotate the field in question (or alternatively annotate the field's 'getter').

example - here only fieldOne will be omitted from the JSON if it is null. fieldTwo will always be included in the JSON regardless of if it is null.

public class Foo {

    @JsonInclude(JsonInclude.Include.NON_NULL) 
    private String fieldOne;

    private String fieldTwo;
}

To omit all null values in the class as a default, annotate the class. Per-field/getter annotations can still be used to override this default if necessary.

example - here fieldOne and fieldTwo will be omitted from the JSON if they are null, respectively, because this is the default set by the class annotation. fieldThree however will override the default and will always be included, because of the annotation on the field.

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Foo {

    private String fieldOne;

    private String fieldTwo;
    
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private String fieldThree;
}

UPDATE

The above is for Jackson 2. For earlier versions of Jackson you need to use:

@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) 

instead of

@JsonInclude(JsonInclude.Include.NON_NULL)

If this update is useful, please upvote ZiglioUK's answer below, it pointed out the newer Jackson 2 annotation long before I updated my answer to use it!

🌐
Java By Examples
javabyexamples.com › control-how-jackson-serializes-null-values
Control How Jackson Serializes Null Values
Here, we're stating @JsonInclude(Include.NON_NULL) to serialize only non-null properties. So the resulting JSON includes the age property but doesn't include null name property. Secondly, we change the default settings of Jackson:
🌐
Mkyong
mkyong.com › home › java › how to ignore null fields with jackson
How to ignore null fields with Jackson | mkyong.com
April 24, 2024 - We can put the @JsonInclude(JsonInclude.Include.NON_NULL) annotation on a specified field to tell Jackson to ignore it if it contains a null value during serialization.
🌐
Baeldung
baeldung.com › home › json › jackson › include null value in json serialization
Include null Value in JSON Serialization | Baeldung
June 21, 2025 - Here, we employ the GsonBuilder to set up a Gson instance using the serializeNulls() method. This configuration ensures that null values are incorporated during serialization, ensuring precise representation in the resulting JSON output, even ...
🌐
Java Guides
javaguides.net › 2019 › 04 › jackson-ignore-null-and-empty-fields-on-serialization.html
Jackson Ignore Null and Empty Fields on Serialization
April 24, 2019 - Jackson provides Include.NON_NULL to ignore fields with Null values and Include.NON_EMPTY to ignore fields with Empty values. By default, Jackson does not ignore Null and Empty fields while writing JSON.
🌐
Baeldung
baeldung.com › home › json › jackson › ignore null fields with jackson
Ignore Null Fields with Jackson | Baeldung
February 9, 2026 - With either approach, Jackson omits the annotated null values during serialization.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Jackson Field Absent vs Null Difference - Java Code Geeks
March 6, 2025 - However, we can use JsonInclude to control how null, empty, and default values are handled. Setting JsonInclude.Include.NON_NULL ensures that null fields are not included in the serialized JSON.
Find elsewhere
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 4116
Serializing and deserialing `null` when wrapping with root name · Issue #4116 · FasterXML/jackson-databind
September 13, 2023 - // both return "null" but could return "{\"Pojo\":null}" ? // are there other cases when the root name is know ? mapper.writer().withRootName("Pojo").writeValueAsString(null) mapper.writerFor(Pojo.class).with(SerializationFeature.WRAP_ROOT_VALUE).writeValueAsString(null) // for now these throw exception but should work if the serialization is allowed ? mapper.readerFor(Pojo.class).with(DeserializationFeature.UNWRAP_ROOT_VALUE).readValue("{\"Pojo\":null}") mapper.reader().withRootName("Pojo").readValue("{\"Pojo\":null}", Pojo.class) // Exception com.fasterxml.jackson.databind.exc.MismatchedInputException: // Cannot deserialize value of type `Pojo` from Null value (token `JsonToken.VALUE_NULL`) A workaround is to wrap the null in another object that is never null but it's less expressive ?
Author: FasterXML
🌐
Davismol
davismol.net › 2016 › 01 › 08 › jackson-how-to-exclude-null-value-properties-from-json-serialization
Jackson: how to exclude null value properties from JSON serialization | Dede Blog
January 8, 2016 - So in summary, this second method ... of null values need to be applied to all classes serialized with that ObjectMapper (assuming, of course, to have access to the ObjectMapper used). The first method, with the annotation at the single class level, allows us to define a different behavior for different classes as needed and for this reason it’s more flexible. See also: Jackson:using @JsonIgnore ...
🌐
Medium
medium.com › @umeshcapg › ignoring-null-fields-with-jackson-in-java-and-spring-boot-cc3ebb0acf99
Ignoring Null Fields with Jackson in Java and Spring Boot 🚀 | by Umesh Kumar Yadav | Medium
June 30, 2025 - If these fields are null, including them in the JSON output as "middleName": null adds no value and may complicate client-side processing. By configuring Jackson to ignore null fields, you ensure that only meaningful data is included, resulting in cleaner and more compact JSON.
🌐
Baeldung
baeldung.com › home › json › jackson › jackson – working with maps and nulls
Jackson – Working With Maps and Nulls
May 2, 2023 - Jackson has a simple but useful way of globally controlling what happens to null values when a Map gets serialized:
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 2288
Custom Serializer omit null values · Issue #2288 · FasterXML/jackson-databind
March 29, 2019 - When we are changing the modifySerializer to not return the TestSerializer, null values are returning as expected and we get the expected result
Author: FasterXML
🌐
HowToDoInJava
howtodoinjava.com › home › jackson › jackson – ignoring null, empty and absent values
Jackson - Ignoring Null, Empty and Absent Values - HowToDoInJava
September 1, 2022 - Learn to ignore the null, empty and absent values during serialization with Jackson using the @JsonInclude as well as SerializationInclusion.
🌐
Stack Overflow
stackoverflow.com › questions › 40678501 › jackson-serialization-with-null
java - Jackson serialization with null - Stack Overflow
November 18, 2016 - If the getters are used and the JsonAnyGetter is removed then the incoming null cannot be serialized as the JsonInclude ignores the field.