Skip to content

Commit 5d4a3e3

Browse files
authored
Allow Play to setConfig + make sure to use correct factory (#1256)
* Use the factory from mapper; now we have setObjectMapper so the factory could change * Allow play to setConfig
1 parent d353eb7 commit 5d4a3e3

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

play-json/jvm/src/main/scala/play/api/libs/json/jackson/JacksonJson.scala

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,27 +274,28 @@ private[play] object JacksonJson {
274274
private var instance = JacksonJson(JsonConfig.settings)
275275

276276
/** Overrides the config. */
277-
private[json] def setConfig(jsonConfig: JsonConfig): Unit = {
277+
private[play] def setConfig(jsonConfig: JsonConfig): Unit = {
278278
instance = JacksonJson(jsonConfig)
279279
}
280280

281281
private[play] def get: JacksonJson = instance
282282
}
283283

284-
private[play] case class JacksonJson(jsonConfig: JsonConfig) {
285-
private val jsonFactory = new JsonFactoryBuilder()
286-
.streamReadConstraints(jsonConfig.streamReadConstraints)
287-
.streamWriteConstraints(jsonConfig.streamWriteConstraints)
288-
.build()
284+
private[play] case class JacksonJson(defaultMapperJsonConfig: JsonConfig) {
289285
private var currentMapper: ObjectMapper = null
290286
private val defaultMapper: ObjectMapper = JsonMapper
291-
.builder(jsonFactory)
287+
.builder(
288+
new JsonFactoryBuilder()
289+
.streamReadConstraints(defaultMapperJsonConfig.streamReadConstraints)
290+
.streamWriteConstraints(defaultMapperJsonConfig.streamWriteConstraints)
291+
.build()
292+
)
292293
.addModules(
293294
new ParameterNamesModule(),
294295
new Jdk8Module(),
295296
new JavaTimeModule(),
296297
new DefaultScalaModule(),
297-
new PlayJsonMapperModule(jsonConfig),
298+
new PlayJsonMapperModule(defaultMapperJsonConfig),
298299
)
299300
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
300301
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
@@ -313,16 +314,16 @@ private[play] case class JacksonJson(jsonConfig: JsonConfig) {
313314
}
314315

315316
private def stringJsonGenerator(out: java.io.StringWriter) =
316-
jsonFactory.createGenerator(out)
317+
mapper().getFactory.createGenerator(out)
317318

318319
def parseJsValue(data: Array[Byte]): JsValue =
319-
mapper().readValue(jsonFactory.createParser(data), classOf[JsValue])
320+
mapper().readValue(mapper().getFactory.createParser(data), classOf[JsValue])
320321

321322
def parseJsValue(input: String): JsValue =
322-
mapper().readValue(jsonFactory.createParser(input), classOf[JsValue])
323+
mapper().readValue(mapper().getFactory.createParser(input), classOf[JsValue])
323324

324325
def parseJsValue(stream: InputStream): JsValue =
325-
mapper().readValue(jsonFactory.createParser(stream), classOf[JsValue])
326+
mapper().readValue(mapper().getFactory.createParser(stream), classOf[JsValue])
326327

327328
private def withStringWriter[T](f: StringWriter => T): T = {
328329
val sw = new StringWriter()

0 commit comments

Comments
 (0)