private static Object digIn ( Object target , String field ) { if ( target instanceof List ) { // The 'field' will tell us what type of objects belong in the list. @ SuppressWarnings ( "unchecked" ) List < Object > list = ( List < Object > ) target ; return digInList ( list , field ) ; } else if ( target instanceof Map ) { // The 'field' will tell us what type of objects belong in the map. @ SuppressWarnings ( "unchecked" ) Map < String , Object > map = ( Map < String , Object > ) target ; return digInMap ( map , field ) ; } else { return digInObject ( target , field ) ; } }
Uses reflection to dig into a chain of objects in preparation for setting a value somewhere within the tree . Gets the value of the given property of the target object and if it is null creates a new instance of the appropriate type and sets it on the target object . Returns the gotten or created value .