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

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

Closed
cowtowncoder opened this issue Nov 19, 2018 · 1 comment
Closed
Milestone

Comments

@cowtowncoder
Copy link
Member

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
@cowtowncoder
Copy link
Member Author

Actually. Now that I think about this bit more, I think this CAN be made to work for 2.10 too.
Not by using globally shared, public JsonMapper, but rather creating a private, non-shared, but static-ly accessible instance. In addition will need to catch, re-throw IOException, but it should work just fine.

Will also need to add unit tests to verify now official support.

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

No branches or pull requests

1 participant