@@ -358,6 +358,8 @@ public void serializeWithType(JsonGenerator g, SerializerProvider provider,
358
358
*<p>
359
359
* NOTE: added to replace those uses of {@link #put(String, JsonNode)}
360
360
* where chaining with 'this' is desired.
361
+ *<p>
362
+ * NOTE: co-variant return type since 2.10
361
363
*
362
364
* @param value to set field to; if null, will be converted
363
365
* to a {@link NullNode} first (to remove field entry, call
@@ -367,26 +369,30 @@ public void serializeWithType(JsonGenerator g, SerializerProvider provider,
367
369
*
368
370
* @since 2.1
369
371
*/
370
- public JsonNode set (String fieldName , JsonNode value )
372
+ @ SuppressWarnings ("unchecked" )
373
+ public <T extends JsonNode > T set (String fieldName , JsonNode value )
371
374
{
372
375
if (value == null ) {
373
376
value = nullNode ();
374
377
}
375
378
_children .put (fieldName , value );
376
- return this ;
379
+ return ( T ) this ;
377
380
}
378
381
379
382
/**
380
383
* Method for adding given properties to this object node, overriding
381
384
* any existing values for those properties.
385
+ *<p>
386
+ * NOTE: co-variant return type since 2.10
382
387
*
383
388
* @param properties Properties to add
384
389
*
385
390
* @return This node after adding/replacing property values (to allow chaining)
386
391
*
387
392
* @since 2.1
388
393
*/
389
- public JsonNode setAll (Map <String ,? extends JsonNode > properties )
394
+ @ SuppressWarnings ("unchecked" )
395
+ public <T extends JsonNode > T setAll (Map <String ,? extends JsonNode > properties )
390
396
{
391
397
for (Map .Entry <String ,? extends JsonNode > en : properties .entrySet ()) {
392
398
JsonNode n = en .getValue ();
@@ -395,25 +401,28 @@ public JsonNode setAll(Map<String,? extends JsonNode> properties)
395
401
}
396
402
_children .put (en .getKey (), n );
397
403
}
398
- return this ;
404
+ return ( T ) this ;
399
405
}
400
406
401
407
/**
402
408
* Method for adding all properties of the given Object, overriding
403
409
* any existing values for those properties.
410
+ *<p>
411
+ * NOTE: co-variant return type since 2.10
404
412
*
405
413
* @param other Object of which properties to add to this object
406
414
*
407
415
* @return This node after addition (to allow chaining)
408
416
*
409
417
* @since 2.1
410
418
*/
411
- public JsonNode setAll (ObjectNode other )
419
+ @ SuppressWarnings ("unchecked" )
420
+ public <T extends JsonNode > T setAll (ObjectNode other )
412
421
{
413
422
_children .putAll (other ._children );
414
- return this ;
423
+ return ( T ) this ;
415
424
}
416
-
425
+
417
426
/**
418
427
* Method for replacing value of specific property with passed
419
428
* value, and returning value (or null if none).
@@ -437,31 +446,37 @@ public JsonNode replace(String fieldName, JsonNode value)
437
446
/**
438
447
* Method for removing field entry from this ObjectNode, and
439
448
* returning instance after removal.
449
+ *<p>
450
+ * NOTE: co-variant return type since 2.10
440
451
*
441
452
* @return This node after removing entry (if any)
442
453
*
443
454
* @since 2.1
444
455
*/
445
- public JsonNode without (String fieldName )
456
+ @ SuppressWarnings ("unchecked" )
457
+ public <T extends JsonNode > T without (String fieldName )
446
458
{
447
459
_children .remove (fieldName );
448
- return this ;
460
+ return ( T ) this ;
449
461
}
450
462
451
463
/**
452
464
* Method for removing specified field properties out of
453
465
* this ObjectNode.
466
+ *<p>
467
+ * NOTE: co-variant return type since 2.10
454
468
*
455
469
* @param fieldNames Names of fields to remove
456
470
*
457
471
* @return This node after removing entries
458
472
*
459
473
* @since 2.1
460
474
*/
461
- public ObjectNode without (Collection <String > fieldNames )
475
+ @ SuppressWarnings ("unchecked" )
476
+ public <T extends JsonNode > T without (Collection <String > fieldNames )
462
477
{
463
478
_children .keySet ().removeAll (fieldNames );
464
- return this ;
479
+ return ( T ) this ;
465
480
}
466
481
467
482
/*
@@ -490,7 +505,7 @@ public JsonNode put(String fieldName, JsonNode value)
490
505
}
491
506
return _children .put (fieldName , value );
492
507
}
493
-
508
+
494
509
/**
495
510
* Method for removing field entry from this ObjectNode.
496
511
* Will return value of the field, if such field existed;
0 commit comments