1515import com .fasterxml .jackson .databind .util .ArrayBuilders ;
1616
1717/**
18- * Basic serializer that can take Json "Object" structure and
18+ * Basic serializer that can take JSON "Object" structure and
1919 * construct a {@link java.util.Map} instance, with typed contents.
2020 *<p>
2121 * Note: for untyped content (one indicated by passing Object.class
@@ -405,8 +405,10 @@ protected final void _readAndBind(JsonParser jp, DeserializationContext ctxt,
405405 } else {
406406 result .put (key , value );
407407 }
408- } catch (UnresolvedForwardReference reference ) {
408+ } catch (UnresolvedForwardReference reference ) {
409409 handleUnresolvedReference (jp , referringAccumulator , key , reference );
410+ } catch (Exception e ) {
411+ wrapAndThrow (e , result , fieldName );
410412 }
411413 }
412414 }
@@ -457,6 +459,8 @@ protected final void _readAndBindStringMap(JsonParser jp, DeserializationContext
457459 }
458460 } catch (UnresolvedForwardReference reference ) {
459461 handleUnresolvedReference (jp , referringAccumulator , fieldName , reference );
462+ } catch (Exception e ) {
463+ wrapAndThrow (e , result , fieldName );
460464 }
461465 }
462466 }
@@ -493,7 +497,7 @@ public Map<Object,Object> _deserializeUsingCreator(JsonParser jp, Deserializatio
493497 try {
494498 result = (Map <Object ,Object >)creator .build (ctxt , buffer );
495499 } catch (Exception e ) {
496- wrapAndThrow (e , _mapType .getRawClass ());
500+ wrapAndThrow (e , _mapType .getRawClass (), propName );
497501 return null ;
498502 }
499503 _readAndBind (jp , ctxt , result );
@@ -504,13 +508,19 @@ public Map<Object,Object> _deserializeUsingCreator(JsonParser jp, Deserializatio
504508 // other property? needs buffering
505509 String fieldName = jp .getCurrentName ();
506510 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 ;
514524 }
515525 buffer .bufferMapProperty (key , value );
516526 }
@@ -519,14 +529,18 @@ public Map<Object,Object> _deserializeUsingCreator(JsonParser jp, Deserializatio
519529 try {
520530 return (Map <Object ,Object >)creator .build (ctxt , buffer );
521531 } catch (Exception e ) {
522- wrapAndThrow (e , _mapType .getRawClass ());
532+ wrapAndThrow (e , _mapType .getRawClass (), null );
523533 return null ;
524534 }
525535 }
526536
537+ @ Deprecated // since 2.5
538+ protected void wrapAndThrow (Throwable t , Object ref ) throws IOException {
539+ wrapAndThrow (t , ref , null );
540+ }
541+
527542 // 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
530544 {
531545 // to handle StackOverflow:
532546 while (t instanceof InvocationTargetException && t .getCause () != null ) {
@@ -540,7 +554,7 @@ protected void wrapAndThrow(Throwable t, Object ref)
540554 if (t instanceof IOException && !(t instanceof JsonMappingException )) {
541555 throw (IOException ) t ;
542556 }
543- throw JsonMappingException .wrapWithPath (t , ref , null );
557+ throw JsonMappingException .wrapWithPath (t , ref , key );
544558 }
545559
546560 private void handleUnresolvedReference (JsonParser jp , MapReferringAccumulator accumulator , Object key ,
0 commit comments