private void setFieldValueFromMap ( final Object parentObject , final FieldAccess field , final Map mapInner ) { Class < ? > fieldClassType = field . type ( ) ; Object value = null ; /* Is the field not a map. */ if ( ! Typ . isMap ( fieldClassType ) ) { if ( ! fieldClassType . isInterface ( ) && ! Typ . isAbstract ( fieldClassType ) ) { value = fromMap ( mapInner , field . type ( ) ) ; } else { Object oClassName = mapInner . get ( "class" ) ; if ( oClassName != null ) { value = fromMap ( mapInner , Reflection . loadClass ( oClassName . toString ( ) ) ) ; } else { value = null ; } } /* REFACTOR: This is at least the third time that I have seen this code in the class. It was either cut and pasted or I forgot I wrote it three times. REFACTOR: */ } else if ( Typ . isMap ( fieldClassType ) ) { Class keyType = ( Class ) field . getParameterizedType ( ) . getActualTypeArguments ( ) [ 0 ] ; Class valueType = ( Class ) field . getParameterizedType ( ) . getActualTypeArguments ( ) [ 1 ] ; Set < Map . Entry > set = mapInner . entrySet ( ) ; Map newMap = new LinkedHashMap ( ) ; for ( Map . Entry entry : set ) { Object evalue = entry . getValue ( ) ; Object key = entry . getKey ( ) ; if ( evalue instanceof ValueContainer ) { evalue = ( ( ValueContainer ) evalue ) . toValue ( ) ; } key = Conversions . coerce ( keyType , key ) ; evalue = Conversions . coerce ( valueType , evalue ) ; newMap . put ( key , evalue ) ; } value = newMap ; } field . setValue ( parentObject , value ) ; }
Inject a map into an object s field .