Skip to content

Commit d634145

Browse files
committed
Merge branch '2.x' into 3.x
2 parents 4d552a7 + bb0ef93 commit d634145

File tree

1 file changed

+29
-24
lines changed

1 file changed

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

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

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

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.*;
109
import tools.jackson.dataformat.cbor.testutil.failure.JacksonTestFailureExpected;
1110

1211
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -15,31 +14,37 @@
1514

1615
public class StringRef599Test extends CBORTestBase
1716
{
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()
2919
.enable(CBORWriteFeature.STRINGREF)
3020
.build());
3121

22+
// [dataformats-binary#599]
23+
@Test
24+
public void testDupsNoStringRef() throws Exception
25+
{
26+
_testStringRef(VANILLA_MAPPER);
27+
}
28+
3229
// [dataformats-binary#599]
3330
@JacksonTestFailureExpected
3431
@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
3638
{
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+
}
4550
}

0 commit comments

Comments
 (0)