Is your feature request related to a problem? Please describe.
In Jackson 2.x, I am wrapping JsonGenerator
to add syntax highlighting.
This is done using a combination of PrettyPrinter
and JsonGeneratorDelegate
. The pretty-printer is stateful, and so I've set a new PrettyPrinter
instance per JsonGenerator
.
In 3.x however, there is no longer any setPrettyPrinter
in JsonGenerator
, so I am coming up short.
Describe the solution you'd like
Ideally, I'd be able to output the same as before via JsonGeneratorDecorator
, and/or at least without copying a lot of resources. Is this possible in 3.x and/or what am I doing wrong? Cant even make any pretty-printing work with 3.0.0-rc10 at the moment
Usage example
This code does not pretty-print (and even if it did, it would not be ok to share the pretty printer).
Additional context
No response
Comment From: cowtowncoder
Ah. This is actually solved by making PrettyPrinter
implement [tools.jackson.core.util.]Instantiatable
.
If so, configured instance is not used as-is, but rather its createInstance()
method is called to create actual instance.
Same works for 2.x as well.
Comment From: skjolber
Tried the Instantiatable
, but there is no way to access the newly constructed PrettyPrinter
instance via the JsonGenerator
(no getter for JsonGeneratorBase._cfgPrettyPrinter
), so fail.
So then was only able to make it work using an ObjectWriteContext
with JsonFactory.createGenerator(..)
.
Is adding a getter for _cfgPrettyPrinter
an alternative? And/or am I missing something here?
Either way, I fear not being able to use JsonGeneratorDecorator
is going to be messy.
Comment From: cowtowncoder
@skjolber Sounds like adding getter for PrettyPrinter
would be an option. If so, I need to add it REALLY quickly now
But quick question: why is access needed in the first place?
Comment From: cowtowncoder
Created https://github.com/FasterXML/jackson-core/issues/1480, will implement.
Comment From: skjolber
But quick question: why is access needed in the first place?
The pretty-printer (SyntaxHighlightingPrettyPrinter
) state is adjusted by the JsonGenerator
wrapper (SyntaxHighlightingJsonGenerator
) in order to get the desired output.
Example 1, Example 2, Example 3.
Comment From: skjolber
Thanks, now works as expected! 💯
Edit: I might be back for a setter too.