summaryrefslogtreecommitdiff
path: root/src/main/scala/spray/json/JsonParserSettings.scala
blob: d07075e1657b810d1864c9546dfd4ac8e5ec351f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package spray.json

trait JsonParserSettings {
  /**
   * The JsonParser uses recursive decent parsing that keeps intermediate values on the stack. To prevent
   * StackOverflowExceptions a limit is enforced on the depth of the parsed JSON structure.
   *
   * As a guideline we tested that one level of depth needs about 300 bytes of stack space.
   *
   * The default is a depth of 1000.
   */
  def maxDepth: Int

  /**
   * Return a copy of this settings object with the `maxDepth` setting changed to the new value.
   */
  def withMaxDepth(newValue: Int): JsonParserSettings
}
object JsonParserSettings {
  val default: JsonParserSettings = SettingsImpl()

  private case class SettingsImpl(
    maxDepth: Int = 1000
  ) extends JsonParserSettings {
    override def withMaxDepth(newValue: Int): JsonParserSettings = copy(maxDepth = newValue)
  }
}