Skip to content

Commit 82f0682

Browse files
authored
Create NonBlockingDeserTest.java (#5002)
1 parent ff62345 commit 82f0682

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package tools.jackson.databind.deser;
2+
3+
import org.junit.jupiter.api.Test;
4+
import tools.jackson.core.JsonParser;
5+
import tools.jackson.core.ObjectReadContext;
6+
import tools.jackson.core.async.ByteBufferFeeder;
7+
import tools.jackson.databind.DeserializationFeature;
8+
import tools.jackson.databind.ObjectMapper;
9+
import tools.jackson.databind.json.JsonMapper;
10+
11+
import java.nio.ByteBuffer;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
15+
/**
16+
* Tests for checking that test deserialization with non-blocking parsers
17+
*/
18+
public class NonBlockingDeserTest
19+
{
20+
record Foo(String bar) {}
21+
22+
/*
23+
/**********************************************************
24+
/* Test methods
25+
/**********************************************************
26+
*/
27+
28+
@Test
29+
public void testNonBlockingParser()
30+
{
31+
final ObjectMapper m = JsonMapper.builder()
32+
//.disable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
33+
.build();
34+
final JsonParser parser =
35+
m.tokenStreamFactory().createNonBlockingByteBufferParser(ObjectReadContext.empty());
36+
final int len = 10;
37+
Foo[] foos = new Foo[len];
38+
for (int i = 0; i < len; ++i) {
39+
foos[i] = new Foo("bar-" + i);
40+
}
41+
try {
42+
((ByteBufferFeeder) parser).feedInput(ByteBuffer.wrap(m.writeValueAsBytes(foos)));
43+
((ByteBufferFeeder) parser).endOfInput();
44+
final Foo[] result = m.readValue(parser, Foo[].class);
45+
assertEquals(len, result.length);
46+
} finally {
47+
parser.close();
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)