JsonMapper rejects JSON arrays over 1000 elements: hardcoded limit, silent failure in Spring Cloud Stream
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 55/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- java, kafka, spring-boot
- Bereich
- backend
Rechercherichtung
Start with the linked upstream commit, then read ContextFunctionCatalogAutoConfiguration.JsonMapperConfiguration#jackson, which unconditionally registers CollectionLimitModule, and LimitedCollectionDeserializer where MAX_ITEMS = 1000 is hardcoded. From there follow JsonMessageConverter#convertFromInternal, which swallows the failure at DEBUG and returns null. A fix means a configurable bound (with an off switch), a WARN or MessageConversionException instead of null, and tests reproducing the 1001-element Payload sample.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
Since 5.1.0 (and 5.0.6), the auto-configured Jackson JsonMapper rejects any JSON array with more than 1000 elements. The limit is hardcoded, and in Spring Cloud Stream the failure is silent, so it is hard to find.
Versions: Spring Cloud Function 5.1.0, Spring Cloud Stream 5.1.0 with the Kafka binder, Spring Boot 4.2.0, Jackson 3.3.0.
Where it happens:
ContextFunctionCatalogAutoConfiguration.JsonMapperConfiguration#jacksonalways registersCollectionLimitModule.LimitedCollectionDeserializerthrowsIllegalStateException: Collection size exceeds limit of 1000whenMAX_ITEMS = 1000is exceeded. There is no property to change or disable it.JsonMessageConverter#convertFromInternalcatches the exception, logs it only at DEBUG and returnsnull.- The function then receives the raw
byte[]payload and fails withClassCastException: class [B cannot be cast to class MyDto. In our setup the message then goes to the DLQ after retries.
This hit us in production after upgrading to Spring Boot 4.2. One of our consumers receives a valid JSON document with a list of about 3700 items. It worked before the upgrade and fails with 5.1.0. The only visible error was the ClassCastException, which points away from the real cause.
The upstream change that added the limit: Ensure deserialization of JSON arrays/collections is bounded.
We understand why a bound is useful. Would it be possible to:
- Make the limit configurable, for example with a
spring.cloud.function.*property, including a way to turn it off. - Report the conversion failure at WARN level or as a
MessageConversionException, instead of returningnulland letting the function fail with aClassCastException.
As a workaround we can declare our own org.springframework.cloud.function.json.JsonMapper bean, since the auto-configured one is @ConditionalOnMissingBean. That also drops the other defaults of the auto-configured mapper, so a property would be much simpler.
Sample
record Payload(List<Integer> items) {}
@Autowired
org.springframework.cloud.function.json.JsonMapper jsonMapper;
// JSON with 1001 elements: {"items":[0,1,2,...,1000]}
jsonMapper.fromJson(json.getBytes(StandardCharsets.UTF_8), Payload.class);
// tools.jackson.databind.DatabindException: Collection size exceeds limit of 1000
In a stream application, a Consumer<Payload> bean bound to a Kafka topic shows the same problem as a ClassCastException.
Thank you!
- Vorherrschende Sprache
- Java
- Sterne
- 1.1k
- Forks
- 655
- Ø Merge
- 4 Std. 54 Min.
- Gemergte PRs (30 T.)
- 10
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus spring-cloud/spring-cloud-function
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
spring-cloud/spring-cloud-function#1542 ·
Maintainer antworten meist innerhalb von 1 Tag
-
GcfJarLayout omits GcfJarLauncher$NestedUrlStreamHandlerFactory, causing NoClassDefFoundError under the GCF invokerEvtl. vergeben @zemiles hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 32/100
spring-cloud/spring-cloud-function#1544 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Kotlin function wrapper treats empty input as no inputEvtl. vergeben @seonwooj0810 hat das heute übernommen. Offen5.0.x backport bug
Schwierigkeit 3/5 Ein halber Tag Anfängerfreundlichkeit 30/100
spring-cloud/spring-cloud-function#1537 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Default JSON mapper collection limit is hard-coded and replaces all collection deserializationOffen5.0.x backport bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 22/100
spring-cloud/spring-cloud-function#1536 ·
Maintainer antworten meist innerhalb von 1 Tag
-
SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion pathsEvtl. vergeben @seonwooj0810 hat das vor 1 Tag übernommen. Offen5.0.x backport bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
spring-cloud/spring-cloud-function#1535 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in spring-cloud/spring-cloud-function
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
bug devops low
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
-
enhancement
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
MDMesh-app/MDMesh#252 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 80/100
Maintainer antworten meist innerhalb von 1 Tag