@@ -790,7 +790,8 @@ public Object findSerializationContentConverter(AnnotatedMember a) {
790
790
791
791
@ Override
792
792
public JavaType refineSerializationType (final MapperConfig <?> config ,
793
- final Annotated a , final JavaType baseType ) throws JsonMappingException
793
+ final Annotated a , final JavaType baseType )
794
+ throws JsonMappingException
794
795
{
795
796
JavaType type = baseType ;
796
797
final TypeFactory tf = config .getTypeFactory ();
@@ -818,15 +819,14 @@ public JavaType refineSerializationType(final MapperConfig<?> config,
818
819
// 27-Apr-2017, tatu: [databind#1592] ignore primitive<->wrapper refinements
819
820
type = type .withStaticTyping ();
820
821
} else {
821
- throw new JsonMappingException ( null ,
822
+ throw _databindException (
822
823
String .format ("Cannot refine serialization type %s into %s; types not related" ,
823
824
type , serClass .getName ()));
824
825
}
825
826
} catch (IllegalArgumentException iae ) {
826
- throw new JsonMappingException ( null ,
827
+ throw _databindException ( iae ,
827
828
String .format ("Failed to widen type %s with annotation (value %s), from '%s': %s" ,
828
- type , serClass .getName (), a .getName (), iae .getMessage ()),
829
- iae );
829
+ type , serClass .getName (), a .getName (), iae .getMessage ()));
830
830
}
831
831
}
832
832
}
@@ -853,15 +853,14 @@ public JavaType refineSerializationType(final MapperConfig<?> config,
853
853
// 27-Apr-2017, tatu: [databind#1592] ignore primitive<->wrapper refinements
854
854
keyType = keyType .withStaticTyping ();
855
855
} else {
856
- throw new JsonMappingException ( null ,
856
+ throw _databindException (
857
857
String .format ("Cannot refine serialization key type %s into %s; types not related" ,
858
858
keyType , keyClass .getName ()));
859
859
}
860
860
} catch (IllegalArgumentException iae ) {
861
- throw new JsonMappingException ( null ,
861
+ throw _databindException ( iae ,
862
862
String .format ("Failed to widen key type of %s with concrete-type annotation (value %s), from '%s': %s" ,
863
- type , keyClass .getName (), a .getName (), iae .getMessage ()),
864
- iae );
863
+ type , keyClass .getName (), a .getName (), iae .getMessage ()));
865
864
}
866
865
}
867
866
type = ((MapLikeType ) type ).withKeyType (keyType );
@@ -889,15 +888,14 @@ public JavaType refineSerializationType(final MapperConfig<?> config,
889
888
// 27-Apr-2017, tatu: [databind#1592] ignore primitive<->wrapper refinements
890
889
contentType = contentType .withStaticTyping ();
891
890
} else {
892
- throw new JsonMappingException ( null ,
891
+ throw _databindException (
893
892
String .format ("Cannot refine serialization content type %s into %s; types not related" ,
894
893
contentType , contentClass .getName ()));
895
894
}
896
895
} catch (IllegalArgumentException iae ) { // shouldn't really happen
897
- throw new JsonMappingException ( null ,
896
+ throw _databindException ( iae ,
898
897
String .format ("Internal error: failed to refine value type of %s with concrete-type annotation (value %s), from '%s': %s" ,
899
- type , contentClass .getName (), a .getName (), iae .getMessage ()),
900
- iae );
898
+ type , contentClass .getName (), a .getName (), iae .getMessage ()));
901
899
}
902
900
}
903
901
type = type .withContentType (contentType );
@@ -1200,10 +1198,9 @@ public JavaType refineDeserializationType(final MapperConfig<?> config,
1200
1198
try {
1201
1199
type = tf .constructSpecializedType (type , valueClass );
1202
1200
} catch (IllegalArgumentException iae ) {
1203
- throw new JsonMappingException ( null ,
1201
+ throw _databindException ( iae ,
1204
1202
String .format ("Failed to narrow type %s with annotation (value %s), from '%s': %s" ,
1205
- type , valueClass .getName (), a .getName (), iae .getMessage ()),
1206
- iae );
1203
+ type , valueClass .getName (), a .getName (), iae .getMessage ()));
1207
1204
}
1208
1205
}
1209
1206
// Then further processing for container types
@@ -1218,10 +1215,9 @@ public JavaType refineDeserializationType(final MapperConfig<?> config,
1218
1215
keyType = tf .constructSpecializedType (keyType , keyClass );
1219
1216
type = ((MapLikeType ) type ).withKeyType (keyType );
1220
1217
} catch (IllegalArgumentException iae ) {
1221
- throw new JsonMappingException ( null ,
1218
+ throw _databindException ( iae ,
1222
1219
String .format ("Failed to narrow key type of %s with concrete-type annotation (value %s), from '%s': %s" ,
1223
- type , keyClass .getName (), a .getName (), iae .getMessage ()),
1224
- iae );
1220
+ type , keyClass .getName (), a .getName (), iae .getMessage ()));
1225
1221
}
1226
1222
}
1227
1223
}
@@ -1235,10 +1231,9 @@ public JavaType refineDeserializationType(final MapperConfig<?> config,
1235
1231
contentType = tf .constructSpecializedType (contentType , contentClass );
1236
1232
type = type .withContentType (contentType );
1237
1233
} catch (IllegalArgumentException iae ) {
1238
- throw new JsonMappingException ( null ,
1234
+ throw _databindException ( iae ,
1239
1235
String .format ("Failed to narrow value type of %s with concrete-type annotation (value %s), from '%s': %s" ,
1240
- type , contentClass .getName (), a .getName (), iae .getMessage ()),
1241
- iae );
1236
+ type , contentClass .getName (), a .getName (), iae .getMessage ()));
1242
1237
}
1243
1238
}
1244
1239
}
@@ -1565,4 +1560,14 @@ private boolean _primitiveAndWrapper(JavaType baseType, Class<?> refinement)
1565
1560
}
1566
1561
return false ;
1567
1562
}
1563
+
1564
+ // @since 2.12
1565
+ private JsonMappingException _databindException (String msg ) {
1566
+ return new JsonMappingException (null , msg );
1567
+ }
1568
+
1569
+ // @since 2.12
1570
+ private JsonMappingException _databindException (Throwable t , String msg ) {
1571
+ return new JsonMappingException (null , msg , t );
1572
+ }
1568
1573
}
0 commit comments