diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/BackReference1516Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/BackReference1516Test.java new file mode 100644 index 0000000000..3c5cf8a595 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/deser/BackReference1516Test.java @@ -0,0 +1,54 @@ +package com.fasterxml.jackson.databind.deser; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonManagedReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; +import org.junit.jupiter.api.Test; + +import java.beans.ConstructorProperties; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +class BackReference1516Test extends DatabindTestUtil { + + static class ParentWithoutCreator { + public String id, name; + + @JsonManagedReference + public ChildObject2 child; + } + + static class ChildObject2 { + public String id, name; + + @JsonBackReference + public ParentWithoutCreator parent; + + @ConstructorProperties({"id", "name", "parent"}) + public ChildObject2(String id, String name, + ParentWithoutCreator parent) { + this.id = id; + this.name = name; + this.parent = parent; + } + } + + private final ObjectMapper MAPPER = newJsonMapper(); + + private final String PARENT_CHILD_JSON = a2q( + "{ 'id': 'abc',\n" + + " 'name': 'Bob',\n" + + " 'child': { 'id': 'def', 'name':'Bert' }\n" + + "}"); + + @Test + void withParentNoCreator() throws Exception { + ParentWithoutCreator result = MAPPER.readValue(PARENT_CHILD_JSON, + ParentWithoutCreator.class); + assertNotNull(result); + assertNotNull(result.child); + assertSame(result, result.child.parent); + } +} diff --git a/src/test/java/com/fasterxml/jackson/failing/BackReference1516Test.java b/src/test/java/com/fasterxml/jackson/failing/BackReference1516Test.java index de2774f847..73f4194557 100644 --- a/src/test/java/com/fasterxml/jackson/failing/BackReference1516Test.java +++ b/src/test/java/com/fasterxml/jackson/failing/BackReference1516Test.java @@ -44,28 +44,6 @@ public ChildObject1(String id, String name, } } - static class ParentWithoutCreator { - public String id, name; - - @JsonManagedReference - public ChildObject2 child; - } - - static class ChildObject2 { - public String id, name; - - @JsonBackReference - public ParentWithoutCreator parent; - - @ConstructorProperties({"id", "name", "parent"}) - public ChildObject2(String id, String name, - ParentWithoutCreator parent) { - this.id = id; - this.name = name; - this.parent = parent; - } - } - private final ObjectMapper MAPPER = newJsonMapper(); private final String PARENT_CHILD_JSON = a2q( @@ -82,13 +60,4 @@ void withParentCreator() throws Exception { assertNotNull(result.child); assertSame(result, result.child.parent); } - - @Test - void withParentNoCreator() throws Exception { - ParentWithoutCreator result = MAPPER.readValue(PARENT_CHILD_JSON, - ParentWithoutCreator.class); - assertNotNull(result); - assertNotNull(result.child); - assertSame(result, result.child.parent); - } }