-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
One feature that I have always resisted, offered by many other json libraries (including jackson-jr
) is access to a global singleton instance (like gson's GSON
). The main reason has been mutability of ObjectMapper
which has meant that it'd effectively be a stateful global singleton, prone to cause problems when one library re-configures it.
But with Jackson 3.0 we finally get truly immutable mappers. Given this, there is no reason why we could not offer simple, efficient and intuitive way for "stock vanilla instance", useful for things like:
- Reading of
Map
s,JsonNode
s - Writing of most types, without customization (or, via
ObjectWriter
, even with minor tweaks) - Use from static and otherwise limited context (
toString()
implementation)
So, let's do it.
After some thought, name shared()
seems appropriate over alternatives considered (default()
is not possible due to Java 8 making it keyword; vanilla()
may not be intuitive; instance()
implies creation of something new).