Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for Configuration of Jackson StreamReadConstraints #9862

Open
jjathman opened this issue Sep 12, 2023 · 4 comments
Open

Allow for Configuration of Jackson StreamReadConstraints #9862

jjathman opened this issue Sep 12, 2023 · 4 comments
Labels
type: enhancement New feature or request

Comments

@jjathman
Copy link

Feature description

With Jackson 2.15 a new StreamReadConstraints was added which limit the maximum size of certain primitive JSON values. In our application we sometimes receive a String within a JSON message which exceeds the default maximum string length now. Having easy configuration of these stream read constraints would be very helpful for us.

Right now, I think the only way to use something other than the default values is to implement a method like this to override the default JsonFactory created by Micronaut:

    @Primary
    @Requires(beans = JacksonConfiguration.class)
    @Singleton
    @BootstrapContextCompatible
    public JsonFactory jsonFactory(JacksonConfiguration jacksonConfiguration) {
        final TSFBuilder<?, ?> jsonFactoryBuilder = JsonFactory.builder();
        StreamReadConstraints streamReadConstraints = StreamReadConstraints.builder()
                .maxStringLength(20 * 1024 * 1024).build()
        jsonFactoryBuilder.streamReadConstraints(streamReadConstraints)
        jacksonConfiguration.getFactorySettings().forEach(jsonFactoryBuilder::configure);
        return jsonFactoryBuilder.build();
    }
@jjathman
Copy link
Author

Note, the default was changed in a subsequent patch release which does fix the immediate problem for us, but I still think this would be nice to make configurable. FasterXML/jackson-core#1014

@yawkat yawkat added the type: enhancement New feature or request label Oct 30, 2023
@yawkat
Copy link
Member

yawkat commented Oct 30, 2023

note that the micronaut-serialization constraints are already configurable through micronaut.serde.maximum-nesting-depth

(doesn't help when you're using jackson-databind ofc)

@ledigiacomo
Copy link

@jjathman is FasterXML/jackson-core#1019 which was made available in version 2.15.2 what you were looking for?

@jjathman
Copy link
Author

jjathman commented Dec 4, 2023

@ledigiacomo I don't think that setting is configurable is using Micronaut's built in Jackson support is it? Maybe I don't understand how that would be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants