Skip to content

spring.jackson.default-property-inclusion is not applied to content inclusion #48343

@tienipia

Description

@tienipia

Title

spring.jackson.default-property-inclusion=non-empty is not applied in Spring Boot 4.0.0

Description

In Spring Boot 4.0.0, configuring:

spring:
  jackson:
    default-property-inclusion: non-empty

does not affect serialization behavior.

Even when the property inclusion is set to non-empty, Jackson still includes empty strings and null values in the serialized output.


Reproduction

Configuration (application.yml)

spring:
  jackson:
    default-property-inclusion: non-empty

Code

private final JsonMapper jsonMapper; // Injected

@Override
public void run(String... args) throws Exception {
    final Map<String, Object> map = new HashMap<>();

    map.put("key1", "");
    map.put("key2", null);
    map.put("key3", "   ");

    jsonMapper.writeValueAsString(map);
    // Expected output: {"key3":"   "}
    // Actual output:   {"key1":"","key2":null,"key3":"   "}
}

Expected Behavior

Keys with empty values ("") or null values should be excluded from serialization when default-property-inclusion is set to non-empty.

Actual Behavior

Empty and null values are still included in the serialized JSON output.

Environment

  • Spring Boot: 4.0.0
  • Jackson: (default version bundled with Spring Boot 4)

Notes

This configuration worked as expected in prior Spring Boot versions.
It appears that spring.jackson.default-property-inclusion is no longer applied or is being ignored in Spring Boot 4.

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions