For Spring Boot 1.2.3, how to set ignore null value in JSON serialization?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Spring Boot 1.2.3 uses Jackson for JSON serialization, so ignoring null values is really a Jackson configuration problem. In that version, you can solve it either globally through Spring Boot configuration or programmatically through the object mapper setup, and you can also control it at the individual class level with @JsonInclude.
Use Jackson's Non-Null Inclusion Rule
At the class level, the basic Jackson answer is JsonInclude.Include.NON_NULL.
If displayName or phoneNumber is null, Jackson leaves it out of the JSON output.
This is the most direct option when only certain DTOs should omit null values.
Configure It Globally In Spring Boot 1.2.3
Spring Boot 1.2.3 also exposes Jackson configuration through properties. The usual global setting is:
Or in YAML:
With this property in place, Spring Boot configures the application's Jackson mapper to skip null values globally.
This is the simplest answer if your whole API should omit null fields by default.
Programmatic Configuration Is Also Possible
If you prefer Java configuration, customize the object mapper builder or object mapper itself.
This gives you explicit Java-side control, which is useful if configuration depends on code or if you want the setting documented in one central configuration class.
Understand The Scope Of The Choice
These approaches differ by scope:
- '
@JsonIncludeaffects one class or one field' - the Spring Boot property affects the application's default mapper
- Java configuration affects the mapper globally unless you create multiple mappers intentionally
That distinction matters because ignoring nulls is an API design choice, not just a formatting tweak.
For example, some clients rely on explicit null to distinguish:
- field intentionally unknown
- field absent because not applicable
If you globally remove nulls, those two cases may collapse into one.
A Simple Controller Example
With non-null inclusion enabled, the response becomes something like:
Without that configuration, Jackson would also emit the null-valued fields.
Field-Level Control Still Works
If only one property should be excluded when null, you can annotate the field directly.
That is useful when you want global defaults unchanged but need one field handled specially.
Common Pitfalls
The biggest mistake is applying a global non-null rule without checking whether API consumers depend on explicit null fields.
Another mistake is mixing class-level and global rules without documenting the intended behavior. The result can become hard to reason about across different DTOs.
People also forget that the setting affects serialization output, not the Java object itself. The fields are still null in memory; they are simply omitted from JSON.
Finally, when maintaining an older Spring Boot version, make sure you use the configuration keys supported by that version instead of copying examples from newer Boot releases blindly.
Summary
- In Spring Boot 1.2.3, ignoring null JSON values is handled through Jackson.
- Use
@JsonInclude(Include.NON_NULL)for class-level or field-level control. - Use
spring.jackson.serialization-inclusion=non_nullfor a global application-wide default. - Java configuration with
Jackson2ObjectMapperBuilderis a good explicit alternative. - Treat null omission as an API contract decision, not just a cosmetic serialization setting.

