playframework / play-json

The Play JSON library
Apache License 2.0
359 stars 134 forks source link

Json.parse fails for strings > 5000000 in length #1054

Open RiteshBM opened 3 weeks ago

RiteshBM commented 3 weeks ago

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

https://github.com/FasterXML/jackson-core/issues/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 ?

mkurz commented 3 weeks ago

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

pjfanning commented 2 weeks ago

@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.

RiteshBM commented 5 days ago

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

pjfanning commented 5 days ago

@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