aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTatu Saloranta <tatu.saloranta@iki.fi>2020-06-15 22:40:48 -0700
committerTatu Saloranta <tatu.saloranta@iki.fi>2020-06-15 22:40:48 -0700
commit02c7345f48c2b5cf4a6eefb51efde37ffa19f403 (patch)
tree770ba881caafa86e0d276ba3f6c2ababf9274906 /src/test
parent9561cfb08bc8a3c0fbafb736a7c9c8418849b95c (diff)
downloadjackson-databind-02c7345f48c2b5cf4a6eefb51efde37ffa19f403.tar.gz
Add failing test for #2759
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/fasterxml/jackson/failing/JsonIdentityInfo2759Test.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/test/java/com/fasterxml/jackson/failing/JsonIdentityInfo2759Test.java b/src/test/java/com/fasterxml/jackson/failing/JsonIdentityInfo2759Test.java
new file mode 100644
index 000000000..d948b0c2a
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/failing/JsonIdentityInfo2759Test.java
@@ -0,0 +1,72 @@
+package com.fasterxml.jackson.failing;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIdentityInfo;
+import com.fasterxml.jackson.annotation.ObjectIdGenerators;
+
+import com.fasterxml.jackson.databind.*;
+
+public class JsonIdentityInfo2759Test extends BaseMapTest
+{
+ static class Bee {
+ public Long id;
+
+ @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
+/// @JsonIdentityReference(alwaysAsId = true)
+// @JsonProperty("hiveId")
+ Hive hive;
+
+ public Bee() { }
+
+ public Bee(Long id, Hive hive) {
+ this.id = id;
+ this.hive = hive;
+ }
+
+ public Hive getHive() {
+ return hive;
+ }
+
+ public void setHive(Hive hive) {
+ this.hive = hive;
+ }
+ }
+
+ static class Hive {
+ public String name;
+ public List<Bee> bees = new ArrayList<>();
+
+ public Long id;
+
+ Hive() { }
+
+ public Hive(Long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public void addBee(Bee bee) {
+ bees.add(bee);
+ }
+ }
+
+ public void testObjectId2759() throws Exception
+ {
+ Hive hive = new Hive(100500L, "main hive");
+ hive.addBee(new Bee(1L, hive));
+
+ ObjectMapper mapper = newJsonMapper();
+ final String json = mapper.writerWithDefaultPrettyPrinter()
+ .writeValueAsString(hive);
+
+ try {
+ mapper.readerFor(JsonNode.class)
+ .with(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY)
+ .readValue(json);
+ } catch (JsonMappingException e) {
+ fail("Should not have duplicates, but JSON content has: "+json);
+ }
+ }
+}