Skip to content

Commit

Permalink
remove stream limit on Jackson ObjectMapper (since 2.15) (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoten committed Sep 8, 2023
1 parent 17ef45a commit af9769a
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.openapitools.jackson.nullable.JsonNullableModule;

import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
Expand Down Expand Up @@ -31,14 +32,23 @@ public static Builder builder() {

public static final class Builder {

private ObjectMapper mapper = JsonMapper //
.builder() //
.disable(MapperFeature.ALLOW_COERCION_OF_SCALARS) //
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) //
.build() //
.registerModule(new JavaTimeModule()) //
.registerModule(new Jdk8Module()) //
.registerModule(new JsonNullableModule());
private ObjectMapper mapper = createObjectMapper();

private static ObjectMapper createObjectMapper() {
ObjectMapper mapper = JsonMapper //
.builder() //
.disable(MapperFeature.ALLOW_COERCION_OF_SCALARS) //
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) //
.build() //
.registerModule(new JavaTimeModule()) //
.registerModule(new Jdk8Module()) //
.registerModule(new JsonNullableModule());
// in Jackson 2.15 a 5MB limit on streams was introduced. Configure this off
StreamReadConstraints streamReadConstraints = StreamReadConstraints.builder()
.maxStringLength(Integer.MAX_VALUE).build();
mapper.getFactory().setStreamReadConstraints(streamReadConstraints);
return mapper;
}

private Predicate<? super Class<?>> validateInConstructor = x -> true;
private Predicate<? super String> validateInControllerMethod = x -> true;
Expand Down

0 comments on commit af9769a

Please sign in to comment.