-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
(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.