@@ -29,6 +29,19 @@ public RecordWithAltCtor(@JsonProperty("id") int id) {
29
29
}
30
30
}
31
31
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
+
32
45
record RecordWithIgnore (int id , @ JsonIgnore String name ) { }
33
46
34
47
record RecordWithRename (int id , @ JsonProperty ("rename" )String name ) { }
@@ -123,14 +136,9 @@ public void testDeserializeSimpleRecord_DisableAnnotationIntrospector() throws E
123
136
124
137
/*
125
138
/**********************************************************************
126
- /* Test methods, reading/writing Record values with annotations
139
+ /* Test methods, alternate constructors
127
140
/**********************************************************************
128
141
*/
129
-
130
- public void testSerializeJsonIgnoreRecord () throws Exception {
131
- String json = MAPPER .writeValueAsString (new RecordWithIgnore (123 , "Bob" ));
132
- assertEquals ("{\" id\" :123}" , json );
133
- }
134
142
135
143
public void testDeserializeWithCanonicalCtorOverride () throws Exception {
136
144
RecordWithCanonicalCtorOverride value = MAPPER .readValue ("{\" id\" :123,\" name\" :\" Bob\" }" ,
@@ -146,6 +154,26 @@ public void testDeserializeWithAltCtor() throws Exception {
146
154
assertEquals ("name2" , value .name ());
147
155
}
148
156
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
+
149
177
public void testSerializeJsonRename () throws Exception {
150
178
String json = MAPPER .writeValueAsString (new RecordWithRename (123 , "Bob" ));
151
179
final Object EXP = map ("id" , Integer .valueOf (123 ), "rename" , "Bob" );
0 commit comments