Skip to content

Commit

Permalink
extended the MAX_String_LENTH for jackson deserialization to make int…
Browse files Browse the repository at this point in the history
…egration tests pass
  • Loading branch information
aamotharald committed Nov 15, 2024
1 parent 5b65c67 commit 3fea6ba
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -127,6 +128,10 @@
*/
public abstract class Deserialization {

//TODO: Make this configurable / injectable ?
public static final int MAX_STRING_LEN_FOR_JACKSON_DESERIALIZATION =
StreamReadConstraints.DEFAULT_MAX_STRING_LEN + 10000000;

/**
* A type reference for deserialization to a Map.
*/
Expand Down Expand Up @@ -201,6 +206,13 @@ public static List<String> readListFrom(JsonNode root, String property) throws I
return list;
}

private static void configureMaxStringLength(ObjectMapper mapper) {
StreamReadConstraints constraints = StreamReadConstraints.builder()
.maxStringLength(MAX_STRING_LEN_FOR_JACKSON_DESERIALIZATION)
.build();
mapper.getFactory().setStreamReadConstraints(constraints);
}

/**
* Registers known sub-types in an {@link ObjectMapper}.
*
Expand All @@ -209,6 +221,8 @@ public static List<String> readListFrom(JsonNode root, String property) throws I
*/
static ObjectMapper registerSubTypesIn(ObjectMapper mapper) {

configureMaxStringLength(mapper);

// features
mapper.registerSubtypes(
PositiveIntegerFeature.class,
Expand Down

0 comments on commit 3fea6ba

Please sign in to comment.