Skip to content

Add JsonMapper.shared() static method #2176

@cowtowncoder

Description

@cowtowncoder

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:

  1. Reading of Maps, JsonNodes
  2. Writing of most types, without customization (or, via ObjectWriter, even with minor tweaks)
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.xIssues to be only tackled for Jackson 3.x, not 2.x

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions