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 #3

Closed
cowtowncoder opened this issue Aug 20, 2017 · 3 comments
Closed

Comments

@cowtowncoder
Copy link
Member

(and make ObjectMapper truly immutable)

One of on-going challenges with Jackson has been mutability of ObjectMapper.
Although it is documented as "config-then-use", users often struggle in figuring out what kinds of changes are allowed. Fundamentally it is also unfortunate that API can not prevent relatively common mistake of trying to re-configure an instance that has already been used.

It would seem like relatively easy way to allow configurability but:

  1. Allow basic use of "just create ObjectMapper instance and go"
  2. Make ObjectMapper truly immutable

and this could be achieved by the addition of a "Builder" class.

As usual, it should be possible to both:

  1. Create builder statically (ObjectMapper.builder()? or .build()?)
  2. Create builder from an existing mapper, starting with its settings (mapper.rebuild()?)

Going forward, perhaps Builder instance should actually be java.io.Serializable?
This might even provide a way to efficiently pass central configuration in distributed systems.
Note, however, that such settings could not pass settings modules change... which actually leads to the big question: how would modules make their changes?

... I will file another RFE for module aspects, then.

@electrum
Copy link

The OkHttp APIs are really nice and work the way you describe. I suggest looking there for inspiration.

@cowtowncoder
Copy link
Member Author

@electrum Thanks. I have briefly looked at OkHttp, and seemed modern and nice API. But worth another look too.

@cowtowncoder
Copy link
Member Author

Moved to FasterXML/jackson-databind#1954

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

No branches or pull requests

2 participants