Skip to content

Commit 3dc7b12

Browse files
committed
Merge branch '2.x' into 3.x
2 parents 94e4019 + 768670d commit 3dc7b12

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project: jackson-databind
2222
#5192: Record types are broken on Android when using R8
2323
(reported by @HelloOO7)
2424
(fix by @pjfanning)
25+
#5197: Add more informative exception for back-references with `record` type
26+
(fix by Joo-Hyuk K)
2527
- Generate SBOMs [JSTEP-14]
2628
2729
2.19.1 (13-Jun-2025)

src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,11 @@ protected void addBackReferenceProperties(DeserializationContext ctxt,
758758
}
759759
}
760760
*/
761+
if (beanDescRef.isRecordType()) {
762+
ctxt.reportBadTypeDefinition(beanDescRef,
763+
"Cannot add back-reference to a `java.lang.Record` type (property '%s')",
764+
refProp.getName());
765+
}
761766
String refName = refProp.findReferenceName();
762767
builder.addBackReferenceProperty(refName, constructSettableProperty(ctxt,
763768
beanDescRef, refProp, refProp.getPrimaryType()));
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package tools.jackson.databind.records;
2+
3+
import java.util.List;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.fasterxml.jackson.annotation.JsonBackReference;
8+
import com.fasterxml.jackson.annotation.JsonManagedReference;
9+
import tools.jackson.databind.ObjectMapper;
10+
import tools.jackson.databind.exc.InvalidDefinitionException;
11+
import tools.jackson.databind.testutil.DatabindTestUtil;
12+
13+
import static org.junit.jupiter.api.Assertions.fail;
14+
15+
// [databind#5188] JsonManagedReference/JsonBackReference exception for records #5188
16+
// (cannot workd
17+
public class RecordBackReference5188Test
18+
extends DatabindTestUtil
19+
{
20+
private final ObjectMapper MAPPER = newJsonMapper();
21+
22+
@Test
23+
public void testRecordDeserializationFail() throws Exception {
24+
final String json = "{\"children\":[{}]}";
25+
26+
try {
27+
MAPPER.readValue(json, Parent.class);
28+
fail("Should not pass");
29+
} catch (InvalidDefinitionException e) {
30+
verifyException(e, "Cannot add back-reference to a `java.lang.Record` type");
31+
verifyException(e, "Invalid type definition for ");
32+
verifyException(e, "(property 'parent')");
33+
}
34+
}
35+
36+
record Child(@JsonBackReference Parent parent) {}
37+
38+
record Parent(@JsonManagedReference List<Child> children) {}
39+
40+
}

0 commit comments

Comments
 (0)