Introduce configurable limits in String, ByteArray and Resource message converters

Author: bclozelCreated Sep 10, 2026Updated Sep 13, 2026
Labelsin: webtype: enhancement

Reactive codecs provide a maxInMemorySize configuration option to limit the amount of in-flight native memory being used at runtime. This doesn't apply to traditional message converters for many reasons.

Many HttpMessageConverters provide ways to limit the memory being allocated on a per message basis, usually through the underlying library (like Jackson). This can be quite complex depending on the message format.

In the case of StringHttpMessageConverter, ByteArrayHttpMessageConverter and ResourceHttpMessageConverter, Spring Framework does not use any library and has control over the allocation. We should introduce a mechanism that developers can use to enforce maximum memory usage on a per decoded message basis. We're not sure yet whether this should be a "shared" mechanism or if each converter should be considered separately. Converters could then throw ContentTooLargeException to better reflect why the request is failing.

This is being considered by the Spring team and requires some more internal discussion and design before we can consider implementations. Contributions are not welcomed at this stage.

Thanks to @waydeshi for reaching out and discussing this matter.

Source: spring-projects/spring-framework