@@ -40,6 +40,20 @@ record SnakeRecord(String myId, String myValue){}
40
40
41
41
record RecordWithJsonDeserialize (int id , @ JsonDeserialize (converter = StringTrimmer .class ) String name ) { }
42
42
43
+ record RecordSingleWriteOnly (@ JsonProperty (access = JsonProperty .Access .WRITE_ONLY ) int id ) { }
44
+
45
+ record RecordSomeWriteOnly (
46
+ @ JsonProperty (access = JsonProperty .Access .WRITE_ONLY ) int id ,
47
+ @ JsonProperty (access = JsonProperty .Access .WRITE_ONLY ) String name ,
48
+ String email ) {
49
+ }
50
+
51
+ record RecordAllWriteOnly (
52
+ @ JsonProperty (access = JsonProperty .Access .WRITE_ONLY ) int id ,
53
+ @ JsonProperty (access = JsonProperty .Access .WRITE_ONLY ) String name ,
54
+ @ JsonProperty (access = JsonProperty .Access .WRITE_ONLY ) String email ) {
55
+ }
56
+
43
57
private final ObjectMapper MAPPER = newJsonMapper ();
44
58
45
59
/*
@@ -204,6 +218,53 @@ public void testDeserializeJsonDeserializeRecord() throws Exception {
204
218
assertEquals (new RecordWithJsonDeserialize (123 , "Bob" ), value );
205
219
}
206
220
221
+ /*
222
+ /**********************************************************************
223
+ /* Test methods, JsonProperty(access=WRITE_ONLY)
224
+ /**********************************************************************
225
+ */
226
+
227
+ public void testSerialize_SingleWriteOnlyParameter () throws Exception {
228
+ String json = MAPPER .writeValueAsString (new RecordSingleWriteOnly (123 ));
229
+
230
+ assertEquals ("{}" , json );
231
+ }
232
+
233
+ // [databind#3897]
234
+ public void testDeserialize_SingleWriteOnlyParameter () throws Exception {
235
+ RecordSingleWriteOnly value = MAPPER .readValue ("{\" id\" :123}" , RecordSingleWriteOnly .class );
236
+
237
+ assertEquals (new RecordSingleWriteOnly (123 ), value );
238
+ }
239
+
240
+ public void testSerialize_SomeWriteOnlyParameter () throws Exception {
241
+ String json =
MAPPER .
writeValueAsString (
new RecordSomeWriteOnly (
123 ,
"Bob" ,
"[email protected] " ));
242
+
243
+ assertEquals (
"{\" email\" :\" [email protected] \" }" ,
json );
244
+ }
245
+
246
+ public void testDeserialize_SomeWriteOnlyParameter () throws Exception {
247
+ RecordSomeWriteOnly value = MAPPER .readValue (
248
+ "{\" id\" :123,\" name\" :\" Bob\" ,\" email\" :\" [email protected] \" }" ,
249
+ RecordSomeWriteOnly .class );
250
+
251
+ assertEquals (
new RecordSomeWriteOnly (
123 ,
"Bob" ,
"[email protected] " ),
value );
252
+ }
253
+
254
+ public void testSerialize_AllWriteOnlyParameter () throws Exception {
255
+ String json =
MAPPER .
writeValueAsString (
new RecordAllWriteOnly (
123 ,
"Bob" ,
"[email protected] " ));
256
+
257
+ assertEquals ("{}" , json );
258
+ }
259
+
260
+ public void testDeserialize_AllWriteOnlyParameter () throws Exception {
261
+ RecordAllWriteOnly value = MAPPER .readValue (
262
+ "{\" id\" :123,\" name\" :\" Bob\" ,\" email\" :\" [email protected] \" }" ,
263
+ RecordAllWriteOnly .class );
264
+
265
+ assertEquals (
new RecordAllWriteOnly (
123 ,
"Bob" ,
"[email protected] " ),
value );
266
+ }
267
+
207
268
/*
208
269
/**********************************************************************
209
270
/* Internal helper methods
0 commit comments