Skip to content

Commit 8caeea2

Browse files
committed
Add a (failing!) test for #2980
1 parent cd2afd6 commit 8caeea2

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/test-jdk14/java/com/fasterxml/jackson/databind/RecordTest.java

+34-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ public RecordWithAltCtor(@JsonProperty("id") int id) {
2929
}
3030
}
3131

32+
// [databind#2980]
33+
record RecordWithDelegation(String value) {
34+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
35+
public RecordWithDelegation(String value) {
36+
this.value = "del:"+value;
37+
}
38+
39+
@JsonValue()
40+
public String getValue() {
41+
return "val:"+value;
42+
}
43+
}
44+
3245
record RecordWithIgnore(int id, @JsonIgnore String name) { }
3346

3447
record RecordWithRename(int id, @JsonProperty("rename")String name) { }
@@ -123,14 +136,9 @@ public void testDeserializeSimpleRecord_DisableAnnotationIntrospector() throws E
123136

124137
/*
125138
/**********************************************************************
126-
/* Test methods, reading/writing Record values with annotations
139+
/* Test methods, alternate constructors
127140
/**********************************************************************
128141
*/
129-
130-
public void testSerializeJsonIgnoreRecord() throws Exception {
131-
String json = MAPPER.writeValueAsString(new RecordWithIgnore(123, "Bob"));
132-
assertEquals("{\"id\":123}", json);
133-
}
134142

135143
public void testDeserializeWithCanonicalCtorOverride() throws Exception {
136144
RecordWithCanonicalCtorOverride value = MAPPER.readValue("{\"id\":123,\"name\":\"Bob\"}",
@@ -146,6 +154,26 @@ public void testDeserializeWithAltCtor() throws Exception {
146154
assertEquals("name2", value.name());
147155
}
148156

157+
// [databind#2980]
158+
public void testDeserializeWithDelegatingCtor() throws Exception {
159+
RecordWithDelegation value = MAPPER.readValue(q("foobar"),
160+
RecordWithDelegation.class);
161+
assertEquals("del:foobar", value.getValue());
162+
163+
assertEquals(q("val:del:foobar"), MAPPER.writeValueAsString(value));
164+
}
165+
166+
/*
167+
/**********************************************************************
168+
/* Test methods, ignorals, renames
169+
/**********************************************************************
170+
*/
171+
172+
public void testSerializeJsonIgnoreRecord() throws Exception {
173+
String json = MAPPER.writeValueAsString(new RecordWithIgnore(123, "Bob"));
174+
assertEquals("{\"id\":123}", json);
175+
}
176+
149177
public void testSerializeJsonRename() throws Exception {
150178
String json = MAPPER.writeValueAsString(new RecordWithRename(123, "Bob"));
151179
final Object EXP = map("id", Integer.valueOf(123), "rename", "Bob");

0 commit comments

Comments
 (0)