@@ -238,10 +238,9 @@ public Character deserialize(JsonParser jp, DeserializationContext ctxt)
238
238
throws IOException , JsonProcessingException
239
239
{
240
240
JsonToken t = jp .getCurrentToken ();
241
- int value ;
242
-
241
+
243
242
if (t == JsonToken .VALUE_NUMBER_INT ) { // ok iff ascii value
244
- value = jp .getIntValue ();
243
+ int value = jp .getIntValue ();
245
244
if (value >= 0 && value <= 0xFFFF ) {
246
245
return Character .valueOf ((char ) value );
247
246
}
@@ -254,7 +253,21 @@ public Character deserialize(JsonParser jp, DeserializationContext ctxt)
254
253
// actually, empty should become null?
255
254
if (text .length () == 0 ) {
256
255
return (Character ) getEmptyValue ();
256
+ }
257
+ } else if (t == JsonToken .START_ARRAY && ctxt .isEnabled (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS )) {
258
+ //Issue#381
259
+ jp .nextToken ();
260
+ final Character value = deserialize (jp , ctxt );
261
+ if (jp .nextToken () != JsonToken .END_ARRAY ) {
262
+ throw ctxt .wrongTokenException (jp , JsonToken .END_ARRAY ,
263
+ "Attempted to unwrap single value array for single '" + _valueClass .getName () + "' value but there was more than a single value in the array"
264
+ );
257
265
}
266
+ return value ;
267
+ } else if (t == JsonToken .VALUE_NULL && !_valueClass .isPrimitive ()) {
268
+ //Issue#unreported
269
+ // This handles the case where the value required is the Character wrapper class and the token is the null token
270
+ return getEmptyValue ();
258
271
}
259
272
throw ctxt .mappingException (_valueClass , t );
260
273
}
@@ -436,6 +449,17 @@ public Number deserialize(JsonParser jp, DeserializationContext ctxt)
436
449
throw ctxt .weirdStringException (text , _valueClass , "not a valid number" );
437
450
}
438
451
}
452
+
453
+ if (t == JsonToken .START_ARRAY && ctxt .isEnabled (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS )) {
454
+ jp .nextToken ();
455
+ final Number value = deserialize (jp , ctxt );
456
+ if (jp .nextToken () != JsonToken .END_ARRAY ) {
457
+ throw ctxt .wrongTokenException (jp , JsonToken .END_ARRAY ,
458
+ "Attempted to unwrap single value array for single '" + _valueClass .getName () + "' value but there was more than a single value in the array"
459
+ );
460
+ }
461
+ return value ;
462
+ }
439
463
// Otherwise, no can do:
440
464
throw ctxt .mappingException (_valueClass , t );
441
465
}
@@ -502,10 +526,19 @@ public BigInteger deserialize(JsonParser jp, DeserializationContext ctxt)
502
526
* Could do by calling BigDecimal.toBigIntegerExact()
503
527
*/
504
528
return jp .getDecimalValue ().toBigInteger ();
529
+ } else if (t == JsonToken .START_ARRAY && ctxt .isEnabled (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS )) {
530
+ jp .nextToken ();
531
+ final BigInteger value = deserialize (jp , ctxt );
532
+ if (jp .nextToken () != JsonToken .END_ARRAY ) {
533
+ throw ctxt .wrongTokenException (jp , JsonToken .END_ARRAY ,
534
+ "Attempted to unwrap single value array for single 'BigInteger' value but there was more than a single value in the array"
535
+ );
536
+ }
537
+ return value ;
505
538
} else if (t != JsonToken .VALUE_STRING ) { // let's do implicit re-parse
506
539
// String is ok too, can easily convert; otherwise, no can do:
507
540
throw ctxt .mappingException (_valueClass , t );
508
- }
541
+ }
509
542
text = jp .getText ().trim ();
510
543
if (text .length () == 0 ) {
511
544
return null ;
@@ -547,6 +580,17 @@ public BigDecimal deserialize(JsonParser jp, DeserializationContext ctxt)
547
580
throw ctxt .weirdStringException (text , _valueClass , "not a valid representation" );
548
581
}
549
582
}
583
+
584
+ if (t == JsonToken .START_ARRAY && ctxt .isEnabled (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS )) {
585
+ jp .nextToken ();
586
+ final BigDecimal value = deserialize (jp , ctxt );
587
+ if (jp .nextToken () != JsonToken .END_ARRAY ) {
588
+ throw ctxt .wrongTokenException (jp , JsonToken .END_ARRAY ,
589
+ "Attempted to unwrap single value array for single 'BigDecimal' value but there was more than a single value in the array"
590
+ );
591
+ }
592
+ return value ;
593
+ }
550
594
// Otherwise, no can do:
551
595
throw ctxt .mappingException (_valueClass , t );
552
596
}
0 commit comments