Skip to content

Commit 02c7345

Browse files
committed
Add failing test for #2759
1 parent 9561cfb commit 02c7345

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
7+
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
8+
9+
import com.fasterxml.jackson.databind.*;
10+
11+
public class JsonIdentityInfo2759Test extends BaseMapTest
12+
{
13+
static class Bee {
14+
public Long id;
15+
16+
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
17+
/// @JsonIdentityReference(alwaysAsId = true)
18+
// @JsonProperty("hiveId")
19+
Hive hive;
20+
21+
public Bee() { }
22+
23+
public Bee(Long id, Hive hive) {
24+
this.id = id;
25+
this.hive = hive;
26+
}
27+
28+
public Hive getHive() {
29+
return hive;
30+
}
31+
32+
public void setHive(Hive hive) {
33+
this.hive = hive;
34+
}
35+
}
36+
37+
static class Hive {
38+
public String name;
39+
public List<Bee> bees = new ArrayList<>();
40+
41+
public Long id;
42+
43+
Hive() { }
44+
45+
public Hive(Long id, String name) {
46+
this.id = id;
47+
this.name = name;
48+
}
49+
50+
public void addBee(Bee bee) {
51+
bees.add(bee);
52+
}
53+
}
54+
55+
public void testObjectId2759() throws Exception
56+
{
57+
Hive hive = new Hive(100500L, "main hive");
58+
hive.addBee(new Bee(1L, hive));
59+
60+
ObjectMapper mapper = newJsonMapper();
61+
final String json = mapper.writerWithDefaultPrettyPrinter()
62+
.writeValueAsString(hive);
63+
64+
try {
65+
mapper.readerFor(JsonNode.class)
66+
.with(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY)
67+
.readValue(json);
68+
} catch (JsonMappingException e) {
69+
fail("Should not have duplicates, but JSON content has: "+json);
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)