playframework/play-json

Json.parse fails for strings > 5000000 in length

RiteshBM opened this issue · 4 comments

Play JSON Version (2.5.x / etc)

2.9.4

API (Scala / Java / Neither / Both)

Scala

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

MacOS 14.3 M1

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

Amazon Cornetto Java 17.0.7

Library Dependencies

com.fasterxml.jackson.core:jackson-databind "2.15.0"
com.fasterxml.jackson.core:jackson-core "2.15.0"
com.fasterxml.jackson.core:jackson-annotations "2.15.0"
com.fasterxml.jackson.module:jackson-module-scala_2.12 "2.15.0"

Expected Behavior

  1. Parsing a JSON String with length > 5000000
  2. Returns a JsValue Object

Actual Behavior

throws an exception: com.fasterxml.jackson.core.exc.StreamConstraintsException: String length (5043551) exceeds the maximum length (5000000)

Jackson version: 2.15.0

Reproducible Test Case

val largeString = "a" * 20 * 1000000
val largeJsonString = s"""{ "key": "$largeString" }"""

Related Issues

FasterXML/jackson-core#1001

I've used Json.parse in multiple places. I think Play doesn't expose a way to configure this limit globally. Will I have to create a custom ObjectMapper everywhere ?

Will take a look at this in the course of upgrading jackson.

@RiteshBM Play does not support Jackson 2.15 or above. Jackson 2.15 introduced StreamReadConstraints and Play has not yet implemented anything to allow users with very large JSON docs to override the default Jackson settings.

Stick with Jackson 2.14.

@pjfanning Does it mean I can't use Play without bypassing this limit if other packages require jackson > 2.14.

@RiteshBM Play does not support Jackson 2.15 or above. Jackson 2.15 introduced StreamReadConstraints and Play has not yet implemented anything to allow users with very large JSON docs to override the default Jackson settings.

Stick with Jackson 2.14.

Try calling this method to override the StreamReadConstraints.

https://www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-core/latest/com/fasterxml/jackson/core/StreamReadConstraints.html