Skip to content

Commit

Permalink
Use ThreadLocalRecyclerPool for Jackson
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo committed Apr 3, 2024
1 parent cadf38e commit 031d0df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.util.JsonRecyclerPools;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
Expand Down Expand Up @@ -158,12 +159,14 @@ public static JsonFactory jsonFactory()
// due to the limits introduced by Jackson 2.15
public static JsonFactoryBuilder jsonFactoryBuilder()
{
// https://github.com/FasterXML/jackson-core/issues/1256
return new JsonFactoryBuilder()
.streamReadConstraints(StreamReadConstraints.builder()
.maxStringLength(Integer.MAX_VALUE)
.maxNestingDepth(Integer.MAX_VALUE)
.maxNumberLength(Integer.MAX_VALUE)
.build());
.build())
.recyclerPool(JsonRecyclerPools.threadLocalPool());
}

private interface ParserConstructor<I>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.util.JsonRecyclerPools;
import com.fasterxml.jackson.databind.JsonNode;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -81,6 +82,13 @@ public void testFactoryHasNoReadConstraints()
assertReadConstraints(jsonFactoryBuilder().build().streamReadConstraints());
}

@Test
public void testFactoryHasThreadLocalRecycler()
{
assertThat(jsonFactory()._getRecyclerPool()).isEqualTo(JsonRecyclerPools.threadLocalPool());
assertThat(jsonFactoryBuilder().build()._getRecyclerPool()).isEqualTo(JsonRecyclerPools.threadLocalPool());
}

@Test
public void testBuilderHasNoReadConstraints()
{
Expand Down

0 comments on commit 031d0df

Please sign in to comment.