Merge branch 'master' of github.com:FasterXML/jackson-databind
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestCyclicTypes.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestCyclicTypes.java
index 86cb185..35f2875 100644
--- a/src/test/java/com/fasterxml/jackson/databind/deser/TestCyclicTypes.java
+++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestCyclicTypes.java
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.databind.deser;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.*;
/**
@@ -47,15 +48,26 @@
static class StringLink extends GenericLink<String> {
}
+ static class Selfie382 {
+ public int id;
+
+ @JsonIgnoreProperties({ "parent", "ignoredRef" })
+ public Selfie382 parent;
+
+ public Selfie382(int id) { this.id = id; }
+ }
+
/*
/**********************************************************
/* Unit tests
/**********************************************************
*/
+ private final ObjectMapper MAPPER = objectMapper();
+
public void testLinked() throws Exception
{
- Bean first = new ObjectMapper().readValue
+ Bean first = MAPPER.readValue
("{\"name\":\"first\", \"next\": { "
+" \"name\":\"last\", \"next\" : null }}",
Bean.class);
@@ -70,17 +82,29 @@
public void testLinkedGeneric() throws Exception
{
- StringLink link = new ObjectMapper().readValue
- ("{\"next\":null}", StringLink.class);
+ StringLink link = MAPPER.readValue("{\"next\":null}", StringLink.class);
assertNotNull(link);
assertNull(link.next);
}
public void testCycleWith2Classes() throws Exception
{
- LinkA a = new ObjectMapper().readValue("{\"next\":{\"a\":null}}", LinkA.class);
+ LinkA a = MAPPER.readValue("{\"next\":{\"a\":null}}", LinkA.class);
assertNotNull(a.next);
LinkB b = a.next;
assertNull(b.a);
}
+
+ // [Issue#382]: Should be possible to ignore cyclic ref
+ public void testIgnoredCycle() throws Exception
+ {
+ Selfie382 self1 = new Selfie382(1);
+ Selfie382 self2 = new Selfie382(2);
+ self1.parent = self2;
+ self2.parent = self1;
+ String json = MAPPER.writeValueAsString(self1);
+ assertNotNull(json);
+ assertEquals(aposToQuotes("{'id':1,'parent':{'id':2}}"), json);
+ }
+
}