Skip to content

Make JsonNode.toString() use shared ObjectMapper to produce valid json #2187

@cowtowncoder

Description

@cowtowncoder

Jackson 2.x has half-assed implementation of JsonNode.toString() which sort-of, mostly works, but:

  1. Not quite, because
  2. Implementation can not access standard JsonGenerator, so it is implemented with a simple, non-complete, code-duplicating writers

At first the plan was to actually make toString() produce visibly non-JSON output, to make it obvious that proper way to serialize JsonNodes is to do use ObjectMapper.writeValueAsString() (or equivalent).
But with #2176 we have a better way: we can produce valid JSON with standard/vanilla settings.
This should be convenient for many "casual JSON" use cases, and would achieve the goals of:

  1. Valid JSON output, if it looks such
  2. No more code duplication

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions