On Wed, Apr 25, 2018 at 8:13 PM,  <[email protected]> wrote:
> On Wednesday, April 25, 2018 at 7:52:01 PM UTC-7, Tatu Saloranta wrote:
>>
>> On Wed, Apr 25, 2018 at 4:16 PM,  <[email protected]> wrote:
>> So: to make sure `PrettyPrinter` works in thread-safe manner, it needs
>> to either:
>>
>> 1. Be stateless (like `MinimalPrettyPrinter`), immutable. OR
>> 2. Implement `com.fasterxml.jackson.core.util.Instantiatable`,
>> implement `createInstance()` method
>>    that creates stateful instance that is not shared across threads
>>
>> `DefaultPrettyPrinter` does the latter. If you want to sub-class it,
>> however, you MUST override `createInstance()`
>> method; otherwise it will probably not work the way you want (since by
>> default it can not create instance of sub-class).
>>
>> So use of `DefaultPrettyPrinter` should be fine without any extra work.
>> Assuming that all code paths in Jackson do use `createInstance`. So
>> one thing that could be useful is to see how
>> your code is creating generators. With that, it should be possible to
>> create actual test case with custom `PrettyPrinter`
>> that verifies that a copy must have been made (keep a flag or
>> something, set on "blueprint" instance, cleared for
>> actual instances created).
>>
>> -+ Tatu +-
>
>
> This is indeed confusing, because I did just use DefaultPrettyPrinter with
> some settings changes, and not a subclass, but the thread behavior was
> clearly still wrong. I am assuming something must be bad about my
> JsonFactory code:
>
> super._createGenerator(out, ctxt).setPrettyPrinter(printer);
>
> I think maybe I need to switch that code to this instead?
>
> return super._createGenerator(out,
> ctxt).setPrettyPrinter(printer.createInstance());

Ah. Any method starting with underscore is considered more or less
implementation-specific.
So you would need to sort of follow control flow from public methods.
Your suggestion sounds reasonable, assuming you know the type of
pretty printer in question
is DefaultPrettyPrinter.

-+ Tatu +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to