From 4d35033c0811d90d1521086a26c95eb023242e0f Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 16 Mar 2024 16:30:03 +0100 Subject: [PATCH] refactor Jackson code to hardcode buffer-recycler refactor Jackson code to hardcode buffer-recycler update jackson scalafmt Update JacksonJson.scala compile issue --- build.sbt | 4 ++-- .../api/libs/json/jackson/JacksonJson.scala | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/build.sbt b/build.sbt index 07344a1c8..60436a456 100644 --- a/build.sbt +++ b/build.sbt @@ -21,12 +21,12 @@ def specs2(scalaVersion: String) = ("org.specs2" %% s"specs2-$n" % "4.20.5") % Test } -val jacksonDatabindVersion = "2.14.3" +val jacksonDatabindVersion = "2.16.2" val jacksonDatabind = Seq( "com.fasterxml.jackson.core" % "jackson-databind" % jacksonDatabindVersion ) -val jacksonVersion = "2.14.3" +val jacksonVersion = "2.16.2" val jacksons = Seq( "com.fasterxml.jackson.core" % "jackson-core", "com.fasterxml.jackson.core" % "jackson-annotations", diff --git a/play-json/jvm/src/main/scala/play/api/libs/json/jackson/JacksonJson.scala b/play-json/jvm/src/main/scala/play/api/libs/json/jackson/JacksonJson.scala index 44f0c090d..4e93de283 100644 --- a/play-json/jvm/src/main/scala/play/api/libs/json/jackson/JacksonJson.scala +++ b/play-json/jvm/src/main/scala/play/api/libs/json/jackson/JacksonJson.scala @@ -14,12 +14,15 @@ import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.ListBuffer import com.fasterxml.jackson.core.JsonFactory +import com.fasterxml.jackson.core.JsonFactoryBuilder import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.core.JsonTokenId +import com.fasterxml.jackson.core.StreamReadConstraints import com.fasterxml.jackson.core.Version import com.fasterxml.jackson.core.json.JsonWriteFeature import com.fasterxml.jackson.core.util.DefaultPrettyPrinter +import com.fasterxml.jackson.core.util.JsonRecyclerPools import com.fasterxml.jackson.databind.Module.SetupContext import com.fasterxml.jackson.databind._ @@ -282,9 +285,17 @@ private[json] object JacksonJson { } private[json] case class JacksonJson(jsonConfig: JsonConfig) { - private val mapper = (new ObjectMapper).registerModule(new PlayJsonMapperModule(jsonConfig)) - - private val jsonFactory = new JsonFactory(mapper) + private val streamReadConstraints = StreamReadConstraints + .builder() + .maxNumberLength(Integer.MAX_VALUE) + .build() + private val jsonFactory = JsonFactory + .builder() + .asInstanceOf[JsonFactoryBuilder] + .streamReadConstraints(streamReadConstraints) + .recyclerPool(JsonRecyclerPools.threadLocalPool()) + .build() + private val mapper = new ObjectMapper(jsonFactory).registerModule(new PlayJsonMapperModule(jsonConfig)) private def stringJsonGenerator(out: java.io.StringWriter) = jsonFactory.createGenerator(out)