Skip to content

Commit

Permalink
try to support typesafe config (#5)
Browse files Browse the repository at this point in the history
* try to support typesafe config

* scalafmt
  • Loading branch information
pjfanning authored Jan 6, 2025
1 parent 42556a7 commit 01c6fcd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ lazy val `play-jsonJVM` = `play-json`.jvm
specs2(scalaVersion.value).map(_.exclude("org.scala-lang.modules", "scala-xml_2.13"))
else
specs2(scalaVersion.value)
} :+ (
} ++ Seq(
"com.typesafe" % "config" % "1.4.3",
"ch.qos.logback" % "logback-classic" % "1.3.15" % Test
),
Test / unmanagedSourceDirectories ++= (docsP / PlayDocsKeys.scalaManualSourceDirectories).value,
Expand Down
10 changes: 10 additions & 0 deletions play-json/jvm/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
play.json {
jackson {
read {
# see https://www.javadoc.io/static/com.fasterxml.jackson.core/jackson-core/2.17.3/com/fasterxml/jackson/core/StreamReadConstraints.html
# these defaults are the same as the defaults in `StreamReadConstraints`
max-nesting-depth = 1000
max-string-length = 20000000
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package play.api.libs.json

import com.fasterxml.jackson.core.StreamReadConstraints
import com.typesafe.config.ConfigFactory

import play.api.libs.json.JsonConfig.defaultMaxPlain
import play.api.libs.json.JsonConfig.defaultMinPlain
Expand Down Expand Up @@ -187,6 +188,10 @@ object JsonConfig {
*/
val preserveZeroDecimalProperty: String = "play.json.serializer.preserveZeroDecimal"

private val playJsonConfig = ConfigFactory
.load()
.getConfig("play.json.jackson")

private[json] def loadScaleLimit: Int = prop(scaleLimitProperty, defaultScaleLimit)(_.toInt)

private[json] def loadDigitsLimit: Int = prop(digitsLimitProperty, defaultDigitsLimit)(_.toInt)
Expand All @@ -198,10 +203,10 @@ object JsonConfig {
private[json] def loadMaxPlain: BigDecimal = prop(maxPlainProperty, defaultMaxPlain)(BigDecimal.exact)

private[json] def loadMaxNestingDepth: Int =
prop(maxNestingDepth, StreamReadConstraints.DEFAULT_MAX_DEPTH)(Integer.parseInt)
prop(maxNestingDepth, playJsonConfig.getInt("read.max-nesting-depth"))(Integer.parseInt)

private[json] def loadMaxStringLength: Int =
prop(maxStringLength, StreamReadConstraints.DEFAULT_MAX_STRING_LEN)(Integer.parseInt)
prop(maxStringLength, playJsonConfig.getInt("read.max-string-length"))(Integer.parseInt)

private[json] def loadPreserveZeroDecimal: Boolean =
prop(preserveZeroDecimalProperty, defaultPreserveZeroDecimal)(_.toBoolean)
Expand Down

0 comments on commit 01c6fcd

Please sign in to comment.