public static Object mapToObject ( Map < String , String > map , Class < ? > c ) { Method m = null ; Object obj = null ; try { obj = c . newInstance ( ) ; } catch ( InstantiationException | IllegalAccessException e ) { log . info ( "instance create fail : " + c . getName ( ) ) ; return null ; } for ( Map . Entry < String , String > entry : map . entrySet ( ) ) { if ( entry . getValue ( ) == null || entry . getValue ( ) . trim ( ) . isEmpty ( ) ) { continue ; } if ( entry . getValue ( ) . equalsIgnoreCase ( "undefined" ) ) { continue ; } try { m = findMethod ( c , getSetMethodName ( entry . getKey ( ) ) ) ; if ( m == null ) { log . info ( "not found mapping method : " + entry . getKey ( ) ) ; continue ; } try { m . invoke ( obj , castValue ( m , m . getParameterTypes ( ) [ 0 ] , entry . getValue ( ) ) ) ; } catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) { log . info ( "method invoke error : " + m . getName ( ) ) ; } } catch ( SecurityException e ) { log . info ( "security exception : " + e . getMessage ( ) ) ; } } return obj ; }
Map to object object .