Skip to content

Allow for Configuration of Jackson StreamReadConstraints #9862

@jjathman

Description

@jjathman

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();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions