Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
}