@@ -64,20 +64,20 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
6464 }
6565 if (type .equals (char .class ) || type .equals (Character .class )) {
6666 if (type .isPrimitive () && element .isNull ())
67- throw new MapperWrongTypeException (context .getField (). getName (), "number" , "null" );
67+ throw new MapperWrongTypeException (context .getFieldName (), "number" , "null" );
6868 String s = element .string (context .getMapper ().isStrict ());
6969 if (s .length () != 1 )
70- throw new MapperException ("Expected string of length 1 for field " + context .getField (). getName () + " but received " + s .length ());
70+ throw new MapperException ("Expected string of length 1 for field " + context .getFieldName () + " but received " + s .length ());
7171 return s .charAt (0 );
7272 }
7373 if (type .equals (Boolean .class ) || type .equals (boolean .class )) {
7474 if (type .isPrimitive () && element .isNull ())
75- throw new MapperWrongTypeException (context .getField (). getName (), "number" , "null" );
75+ throw new MapperWrongTypeException (context .getFieldName (), "number" , "null" );
7676 return element .bool (context .getMapper ().isStrict ());
7777 }
7878 if (Number .class .isAssignableFrom (type ) || type .isPrimitive ()) {
7979 if (type .isPrimitive () && element .isNull ())
80- throw new MapperWrongTypeException (context .getField (). getName (), "number" , "null" );
80+ throw new MapperWrongTypeException (context .getFieldName (), "number" , "null" );
8181 if (type .equals (int .class ) || type .equals (Integer .class ))
8282 return element .number (context .getMapper ().isStrict ()).intValue ();
8383 if (type .equals (long .class ) || type .equals (Long .class ))
@@ -95,9 +95,9 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
9595 return element .number (context .getMapper ().isStrict ());
9696 }
9797 } catch (AbstractCoercingException ex ) {
98- throw new MapperWrongTypeException (context .getField (). getName () , "string" , Helpers .typeName (element ));
98+ throw new MapperWrongTypeException (context .getField () != null ? context . getFieldName () : "" , "string" , Helpers .typeName (element ));
9999 }
100- throw new MapperWrongTypeException (context .getField (). getName (), "primitive" , Helpers .typeName (element ));
100+ throw new MapperWrongTypeException (context .getFieldName (), "primitive" , Helpers .typeName (element ));
101101 }
102102
103103 public Class <?>[] getSupportedTypes () {
@@ -157,7 +157,7 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
157157 } catch (InstantiationException | IllegalAccessException e ) {
158158 throw new RuntimeException (e );
159159 } catch (AbstractCoercingException ex ) {
160- throw new MapperWrongTypeException (context .getField (). getName (), "array" , Helpers .typeName (element ));
160+ throw new MapperWrongTypeException (context .getFieldName (), "array" , Helpers .typeName (element ));
161161 }
162162 }
163163
@@ -216,7 +216,7 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
216216 } catch (InstantiationException | IllegalAccessException e ) {
217217 throw new RuntimeException (e );
218218 } catch (AbstractCoercingException ex ) {
219- throw new MapperWrongTypeException (context .getField (). getName (), "object" , Helpers .typeName (element ));
219+ throw new MapperWrongTypeException (context .getFieldName (), "object" , Helpers .typeName (element ));
220220 }
221221 }
222222
@@ -284,7 +284,7 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
284284 return new Timestamp (date .getTime ());
285285 throw new MapperException ("Unsupported date type '" + type .getName () + "'" );
286286 } catch (ParseException | NumberFormatException | AbstractCoercingException ex ) {
287- throw new MapperException ("Failed to parse date '" + element .string () + "'" + (context .getField () != null ? (" for field '" + context .getField (). getName () + "'" ) : "" ));
287+ throw new MapperException ("Failed to parse date '" + element .string () + "'" + (context .getField () != null ? (" for field '" + context .getFieldName () + "'" ) : "" ));
288288 }
289289 }
290290
@@ -311,13 +311,13 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
311311 if (type .equals (AbstractElement .class ))
312312 return element ;
313313 if (type .equals (AbstractNull .class ) && !(element instanceof AbstractNull ))
314- throw new MapperWrongTypeException (context .getField (). getName (), "null" , Helpers .typeName (element ));
314+ throw new MapperWrongTypeException (context .getFieldName (), "null" , Helpers .typeName (element ));
315315 if (type .equals (AbstractPrimitive .class ) && !(element instanceof AbstractPrimitive ))
316- throw new MapperWrongTypeException (context .getField (). getName (), "primitive" , Helpers .typeName (element ));
316+ throw new MapperWrongTypeException (context .getFieldName (), "primitive" , Helpers .typeName (element ));
317317 if (type .equals (AbstractObject .class ) && !(element instanceof AbstractObject ))
318- throw new MapperWrongTypeException (context .getField (). getName (), "object" , Helpers .typeName (element ));
318+ throw new MapperWrongTypeException (context .getFieldName (), "object" , Helpers .typeName (element ));
319319 if (type .equals (AbstractArray .class ) && !(element instanceof AbstractArray ))
320- throw new MapperWrongTypeException (context .getField (). getName (), "array" , Helpers .typeName (element ));
320+ throw new MapperWrongTypeException (context .getFieldName (), "array" , Helpers .typeName (element ));
321321 return element ;
322322 }
323323
@@ -368,7 +368,7 @@ public AbstractElement toAbstract(MapperContext context, Object value) throws Ma
368368 public Object fromAbstract (MapperContext context , AbstractElement element , Class type ) throws MapperException {
369369 if (type .isEnum ()) {
370370 if (!element .isString ())
371- throw new MapperWrongTypeException (context .getField (). getName (), "string" , Helpers .typeName (element ));
371+ throw new MapperWrongTypeException (context .getFieldName (), "string" , Helpers .typeName (element ));
372372 try {
373373 return Enum .valueOf (type , element .string ());
374374 } catch (IllegalArgumentException ex ) {
@@ -378,7 +378,7 @@ public Object fromAbstract(MapperContext context, AbstractElement element, Class
378378 if (type .equals (UUID .class ))
379379 return UUID .fromString (element .string ());
380380 if (!element .isObject ())
381- throw new MapperWrongTypeException (context .getField (). getName (), "object" , Helpers .typeName (element ));
381+ throw new MapperWrongTypeException (context .getFieldName (), "object" , Helpers .typeName (element ));
382382 MapperTypeSpec spec = MapperTypeSpec .get (type );
383383 if (spec == null )
384384 throw new MapperException ("Unmappable type '" + type .getName () + "'" );
0 commit comments