Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Builder pattern for creating configured ObjectMapper instances #1954

Closed
cowtowncoder opened this issue Mar 1, 2018 · 1 comment
Closed

Comments

@cowtowncoder
Copy link
Member

(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.

@cowtowncoder
Copy link
Member Author

Actually: partial implementation can be (and has been) backported in 2.10. Differences from full implementation:

  1. ObjectMapper (and subtypes) are not fully immutable: Builder is basically a simple facade over calls to configure mapper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant