Skip to content

Remove ObjectMapper.setSerializationInclusion() from 3.0 (deprecate in 2.20) #5270

Description

@cowtowncoder

(note: this is retroactive issue -- actual removal done before 3.0.0-rc1 release)
(note: inspired by #5269)

With 3.0, ObjectMapper becomes immutable: this is achieved by removing all setXxx() methods (and other mutators). This includes setSerializationInclusion().

The replacement for:

ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

is

ObjectMapper mapper = JsonMapper.builder()
    .changeDefaultPropertyInclusion(incl -> incl.withValueInclusion(JsonInclude.Include.NON_NULL))
    .build();

OR for also content (of arrays, Collections, Maps);

ObjectMapper mapper = JsonMapper.builder()
    .changeDefaultPropertyInclusion(incl -> incl.withValueInclusion(JsonInclude.Include.NON_NULL)
       .withContentInclusion(JsonInclude.Include.NON_NULL)
    )
    .build();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.0Issue planned for initial 3.0 release3.0-release-notesIssues relevant for 3.0 release notes.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions