Skip to content

[REQ] Jackson's ObjectMapper is set up using JsonMapper builder #12714

@welandaz

Description

@welandaz

Is your feature request related to a problem? Please describe.

When Jackson serialisation/deserialisation is used, it generates the JSON class and set's up the ObjectMapper attribute in a way, which is deprecated since Jackson 2.13.
Example of what it looks right now:

public JSON() {
    mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
    mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, true);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
    mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
    mapper.setDateFormat(new RFC3339DateFormat());
    mapper.registerModule(new JavaTimeModule());
  }

Currently, when this is compiled, it generates warnings and in case -Werror compiler flag is set - will obviously fail.

Describe the solution you'd like

Since version 2.13, it is recommended to use JsonMapper builder to configure ObjectMapper (available since Jackson 2.10)

Describe alternatives you've considered

I'm not sure which versions of Jackson are supported, but in case its 2.10.x and up - I think it makes sense to fully generate the configuration using JsonMapper and move away from setting it up via ObjectMapper.

Otherwise, the generated code could stay the same for versions lower than 2.13 and be different if that version (or higher) is used

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