Skip to content

Add Builder pattern for creating configured ObjectMapper instances #1954

@cowtowncoder

Description

@cowtowncoder

(from FasterXML/jackson3-dev#3)

To support true, full thread-safety of ObjectMapper instances it is necessary to remove mutability. One proven way is to require construction of instances via "builder" style construction.
Something like:

ObjectMapper mapper = ObjectMapper.builder()
    .disable(MapperFeature.INFER_PROPERTY_MUTATORS)
    .build();

in which changes to configuration may be chained.
In addition to immutability, this will also make it much easier to construct properly typed sub-classes of ObjectMapper needed mainly (for now) for handling other data formats like XML, CSV, Smile and CBOR.

Beyond adding build() and builders, we should also add rebuild() method which will create builder from an existing mapper instance. This will allow simpler delegation of construction process.

Finally, JDK serializability of mappers can be changed to be simpler and safer process as we can retain builder information, including registered modules, and serialize that, instead of all the state actual mappers have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions