private static void merge ( Object m1 ) { if ( m1 instanceof Map ) { Iterator < Object > fieldNames = ( ( Map < Object , Object > ) m1 ) . keySet ( ) . iterator ( ) ; String fieldName = null ; while ( fieldNames . hasNext ( ) ) { fieldName = String . valueOf ( fieldNames . next ( ) ) ; Object field1 = ( ( Map < String , Object > ) m1 ) . get ( fieldName ) ; if ( field1 != null ) { if ( field1 instanceof Map || field1 instanceof List ) { merge ( field1 ) ; // Overwrite previous value when the field1 can not be expanded further } else if ( field1 instanceof String ) { // Retrieve values from ConfigInjection.class Object injectValue = ConfigInjection . getInjectValue ( ( String ) field1 ) ; ( ( Map < String , Object > ) m1 ) . put ( fieldName , injectValue ) ; } } } } else if ( m1 instanceof List ) { for ( int i = 0 ; i < ( ( List < Object > ) m1 ) . size ( ) ; i ++ ) { Object field1 = ( ( List < Object > ) m1 ) . get ( i ) ; if ( field1 instanceof Map || field1 instanceof List ) { merge ( field1 ) ; // Overwrite previous value when the field1 can not be expanded further } else if ( field1 instanceof String ) { // Retrieve values from ConfigInjection.class Object injectValue = ConfigInjection . getInjectValue ( ( String ) field1 ) ; ( ( List < Object > ) m1 ) . set ( i , injectValue ) ; } } } }
Search the config map recursively expand List and Map level by level util no further expand