Skip to content

Commit 8700f19

Browse files
keremncjenkins
authored andcommitted
util-jackson: share PrettyPrinter properly
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
1 parent dfc1c17 commit 8700f19

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

util-jackson/src/main/scala/com/twitter/util/jackson/ScalaObjectMapper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ object ScalaObjectMapper {
412412

413413
private[jackson] object ArrayElementsOnNewLinesPrettyPrinter extends DefaultPrettyPrinter {
414414
_arrayIndenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE
415-
override def createInstance(): DefaultPrettyPrinter = this
415+
override def createInstance(): DefaultPrettyPrinter = new DefaultPrettyPrinter(this)
416416
}
417417

418418
/**

0 commit comments

Comments
 (0)