Skip to content

Commit bb0ef93

Browse files
committed
Merge branch '2.19' into 2.x
2 parents 7f45555 + eb550ff commit bb0ef93

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed
Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.fasterxml.jackson.dataformat.cbor.tofix;
22

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
3+
import java.util.Arrays;
44

5+
import com.fasterxml.jackson.core.JsonToken;
56
import com.fasterxml.jackson.databind.ObjectMapper;
67

7-
import com.fasterxml.jackson.dataformat.cbor.CBORGenerator;
8-
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase;
8+
import com.fasterxml.jackson.dataformat.cbor.*;
99
import com.fasterxml.jackson.dataformat.cbor.testutil.failure.JacksonTestFailureExpected;
1010

1111
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -14,31 +14,37 @@
1414

1515
public class StringRef599Test extends CBORTestBase
1616
{
17-
static class AB599 {
18-
public String a;
19-
public String b;
20-
}
21-
22-
@JsonIgnoreProperties(ignoreUnknown = true)
23-
static class B599 {
24-
public String b;
25-
}
26-
27-
private final ObjectMapper MAPPER = cborMapper(cborFactoryBuilder()
17+
private final ObjectMapper VANILLA_MAPPER = cborMapper();
18+
private final ObjectMapper REF_MAPPER = cborMapper(cborFactoryBuilder()
2819
.enable(CBORGenerator.Feature.STRINGREF)
2920
.build());
3021

22+
// [dataformats-binary#599]
23+
@Test
24+
public void testDupsNoStringRef() throws Exception
25+
{
26+
_testStringRef(VANILLA_MAPPER);
27+
}
28+
3129
// [dataformats-binary#599]
3230
@JacksonTestFailureExpected
3331
@Test
34-
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
3538
{
36-
AB599 ab = new AB599();
37-
ab.a = "foo";
38-
// important: has to be same String value to use StringRef
39-
ab.b = ab.a;
40-
byte[] cbor = MAPPER.writeValueAsBytes(ab);
41-
B599 b = MAPPER.readValue(cbor, B599.class);
42-
assertEquals(ab.b, b.b);
43-
}
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.getText());
47+
assertToken(JsonToken.END_ARRAY, p.nextToken());
48+
}
49+
}
4450
}

0 commit comments

Comments
 (0)