Skip to content

Commit

Permalink
util-jackson: share PrettyPrinter properly
Browse files Browse the repository at this point in the history
The `PrettyPrinter` configured for a Jackson `ObjectWriter` is shared between all downstream `JsonGenerator`s. To make this thread-safe (in order to prevent multiple generators from corrupting the shared indentation level), a class derived from `PrettyPrinter` can also inherit from `Instantiable`, which basically turns the `ObjectWriter`-level `PrettyPrinter` into a factory that produces a new `PrettyPrinter` for each generator.

Since `util-jackson`'s `ArrayElementsOnNewLinesPrettyPrinter` inherits from `DefaultPrettyPrinter`, which has state that must be protected from corruption, we need to abide by this factory pattern.

Differential Revision: https://phabricator.twitter.biz/D1167308
  • Loading branch information
keremnc authored and jenkins committed Aug 29, 2024
1 parent dfc1c17 commit 8700f19
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ object ScalaObjectMapper {

private[jackson] object ArrayElementsOnNewLinesPrettyPrinter extends DefaultPrettyPrinter {
_arrayIndenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE
override def createInstance(): DefaultPrettyPrinter = this
override def createInstance(): DefaultPrettyPrinter = new DefaultPrettyPrinter(this)
}

/**
Expand Down

0 comments on commit 8700f19

Please sign in to comment.