15
15
import com .fasterxml .jackson .databind .util .ArrayBuilders ;
16
16
17
17
/**
18
- * Basic serializer that can take Json "Object" structure and
18
+ * Basic serializer that can take JSON "Object" structure and
19
19
* construct a {@link java.util.Map} instance, with typed contents.
20
20
*<p>
21
21
* Note: for untyped content (one indicated by passing Object.class
@@ -405,8 +405,10 @@ protected final void _readAndBind(JsonParser jp, DeserializationContext ctxt,
405
405
} else {
406
406
result .put (key , value );
407
407
}
408
- } catch (UnresolvedForwardReference reference ) {
408
+ } catch (UnresolvedForwardReference reference ) {
409
409
handleUnresolvedReference (jp , referringAccumulator , key , reference );
410
+ } catch (Exception e ) {
411
+ wrapAndThrow (e , result , fieldName );
410
412
}
411
413
}
412
414
}
@@ -457,6 +459,8 @@ protected final void _readAndBindStringMap(JsonParser jp, DeserializationContext
457
459
}
458
460
} catch (UnresolvedForwardReference reference ) {
459
461
handleUnresolvedReference (jp , referringAccumulator , fieldName , reference );
462
+ } catch (Exception e ) {
463
+ wrapAndThrow (e , result , fieldName );
460
464
}
461
465
}
462
466
}
@@ -493,7 +497,7 @@ public Map<Object,Object> _deserializeUsingCreator(JsonParser jp, Deserializatio
493
497
try {
494
498
result = (Map <Object ,Object >)creator .build (ctxt , buffer );
495
499
} catch (Exception e ) {
496
- wrapAndThrow (e , _mapType .getRawClass ());
500
+ wrapAndThrow (e , _mapType .getRawClass (), propName );
497
501
return null ;
498
502
}
499
503
_readAndBind (jp , ctxt , result );
@@ -504,13 +508,19 @@ public Map<Object,Object> _deserializeUsingCreator(JsonParser jp, Deserializatio
504
508
// other property? needs buffering
505
509
String fieldName = jp .getCurrentName ();
506
510
Object key = _keyDeserializer .deserializeKey (fieldName , ctxt );
507
- Object value ;
508
- if (t == JsonToken .VALUE_NULL ) {
509
- value = valueDes .getNullValue ();
510
- } else if (typeDeser == null ) {
511
- value = valueDes .deserialize (jp , ctxt );
512
- } else {
513
- value = valueDes .deserializeWithType (jp , ctxt , typeDeser );
511
+ Object value ;
512
+
513
+ try {
514
+ if (t == JsonToken .VALUE_NULL ) {
515
+ value = valueDes .getNullValue ();
516
+ } else if (typeDeser == null ) {
517
+ value = valueDes .deserialize (jp , ctxt );
518
+ } else {
519
+ value = valueDes .deserializeWithType (jp , ctxt , typeDeser );
520
+ }
521
+ } catch (Exception e ) {
522
+ wrapAndThrow (e , _mapType .getRawClass (), propName );
523
+ return null ;
514
524
}
515
525
buffer .bufferMapProperty (key , value );
516
526
}
@@ -519,14 +529,18 @@ public Map<Object,Object> _deserializeUsingCreator(JsonParser jp, Deserializatio
519
529
try {
520
530
return (Map <Object ,Object >)creator .build (ctxt , buffer );
521
531
} catch (Exception e ) {
522
- wrapAndThrow (e , _mapType .getRawClass ());
532
+ wrapAndThrow (e , _mapType .getRawClass (), null );
523
533
return null ;
524
534
}
525
535
}
526
536
537
+ @ Deprecated // since 2.5
538
+ protected void wrapAndThrow (Throwable t , Object ref ) throws IOException {
539
+ wrapAndThrow (t , ref , null );
540
+ }
541
+
527
542
// note: copied from BeanDeserializer; should try to share somehow...
528
- protected void wrapAndThrow (Throwable t , Object ref )
529
- throws IOException
543
+ protected void wrapAndThrow (Throwable t , Object ref , String key ) throws IOException
530
544
{
531
545
// to handle StackOverflow:
532
546
while (t instanceof InvocationTargetException && t .getCause () != null ) {
@@ -540,7 +554,7 @@ protected void wrapAndThrow(Throwable t, Object ref)
540
554
if (t instanceof IOException && !(t instanceof JsonMappingException )) {
541
555
throw (IOException ) t ;
542
556
}
543
- throw JsonMappingException .wrapWithPath (t , ref , null );
557
+ throw JsonMappingException .wrapWithPath (t , ref , key );
544
558
}
545
559
546
560
private void handleUnresolvedReference (JsonParser jp , MapReferringAccumulator accumulator , Object key ,
0 commit comments