Skip to content

[BUG] [JAVA-SPRING] 7.24.0: generated field-level @JsonInclude(NON_NULL) overrides project-wide ObjectMapper inclusion #24401

Description

@gs-covariance
Description

Since 7.24.0 (via #23993), JavaSpring/pojo.mustache emits @JsonInclude(JsonInclude.Include.NON_NULL) on every optional non-nullable field.

Field-level @JsonInclude takes precedence over the project ObjectMapper inclusion (e.g. Spring Boot's spring.jackson.default-property-inclusion=non_empty). On upgrade, projects with a stricter global setting silently observe a wire change: fields that were previously omitted (empty collections, empty strings) begin to serialize because per-field NON_NULL is looser than the project default.

What's the recommended path for consumers who need the project ObjectMapper to remain the source of truth for inclusion policy? Field-level @JsonInclude on generated models overrides any global setting, so projects relying on spring.jackson.default-property-inclusion (or an equivalent customizer) can no longer enforce it uniformly on generated types.

Reproduction (for context)

Spring Boot application.yml:

spring:
  jackson:
    default-property-inclusion: non_empty

Optional non-nullable String / List / Map<K,V> fields on a generated model. Response body on 7.23 omits empty values (global NON_EMPTY); on 7.24 emits "field": "", "list": [], "map": {} (field-level NON_NULL wins).

openApiNullable=false, Spring Boot 3.x, Jackson 2.x. Verified live.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions