|
1 | 1 | package tools.jackson.dataformat.cbor.tofix;
|
2 | 2 |
|
3 |
| -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 3 | +import java.util.Arrays; |
4 | 4 |
|
| 5 | +import tools.jackson.core.JsonToken; |
5 | 6 | import tools.jackson.databind.ObjectMapper;
|
6 | 7 |
|
7 |
| -import tools.jackson.dataformat.cbor.CBORGenerator; |
8 |
| -import tools.jackson.dataformat.cbor.CBORTestBase; |
9 |
| -import tools.jackson.dataformat.cbor.CBORWriteFeature; |
| 8 | +import tools.jackson.dataformat.cbor.*; |
10 | 9 | import tools.jackson.dataformat.cbor.testutil.failure.JacksonTestFailureExpected;
|
11 | 10 |
|
12 | 11 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
15 | 14 |
|
16 | 15 | public class StringRef599Test extends CBORTestBase
|
17 | 16 | {
|
18 |
| - static class AB599 { |
19 |
| - public String a; |
20 |
| - public String b; |
21 |
| - } |
22 |
| - |
23 |
| - @JsonIgnoreProperties(ignoreUnknown = true) |
24 |
| - static class B599 { |
25 |
| - public String b; |
26 |
| - } |
27 |
| - |
28 |
| - private final ObjectMapper MAPPER = cborMapper(cborFactoryBuilder() |
| 17 | + private final ObjectMapper VANILLA_MAPPER = cborMapper(); |
| 18 | + private final ObjectMapper REF_MAPPER = cborMapper(cborFactoryBuilder() |
29 | 19 | .enable(CBORWriteFeature.STRINGREF)
|
30 | 20 | .build());
|
31 | 21 |
|
| 22 | + // [dataformats-binary#599] |
| 23 | + @Test |
| 24 | + public void testDupsNoStringRef() throws Exception |
| 25 | + { |
| 26 | + _testStringRef(VANILLA_MAPPER); |
| 27 | + } |
| 28 | + |
32 | 29 | // [dataformats-binary#599]
|
33 | 30 | @JacksonTestFailureExpected
|
34 | 31 | @Test
|
35 |
| - public void testStringRef() throws Exception |
| 32 | + public void testDupsWithStringRef() throws Exception |
| 33 | + { |
| 34 | + _testStringRef(REF_MAPPER); |
| 35 | + } |
| 36 | + |
| 37 | + private void _testStringRef(ObjectMapper mapper) throws Exception |
36 | 38 | {
|
37 |
| - AB599 ab = new AB599(); |
38 |
| - ab.a = "foo"; |
39 |
| - // important: has to be same String value to use StringRef |
40 |
| - ab.b = ab.a; |
41 |
| - byte[] cbor = MAPPER.writeValueAsBytes(ab); |
42 |
| - B599 b = MAPPER.readValue(cbor, B599.class); |
43 |
| - assertEquals(ab.b, b.b); |
44 |
| - } |
| 39 | + byte[] cbor = mapper.writeValueAsBytes(Arrays.asList("foo", "foo")); |
| 40 | + try (CBORParser p = cborParser(cbor)) { |
| 41 | + assertToken(JsonToken.START_ARRAY, p.nextToken()); |
| 42 | + assertToken(JsonToken.VALUE_STRING, p.nextToken()); |
| 43 | + // important! Skip String value |
| 44 | + assertToken(JsonToken.VALUE_STRING, p.nextToken()); |
| 45 | + // equally important; try to check second instance |
| 46 | + assertEquals("foo", p.getString()); |
| 47 | + assertToken(JsonToken.END_ARRAY, p.nextToken()); |
| 48 | + } |
| 49 | + } |
45 | 50 | }
|
0 commit comments