void digReplaceContent ( Map < String , Object > map ) { map . entrySet ( ) . stream ( ) . forEach ( entry -> { Object value = entry . getValue ( ) ; if ( value instanceof Map ) { digReplaceContent ( ( Map < String , Object > ) value ) ; } else { LOGGER . debug ( "Leaf node found = {}, checking for any external json file..." , value ) ; if ( value != null && value . toString ( ) . contains ( JSON_PAYLOAD_FILE ) ) { LOGGER . info ( "Found external JSON file place holder = {}. Replacing with content" , value ) ; String valueString = value . toString ( ) ; String token = getJsonFilePhToken ( valueString ) ; if ( token != null && token . startsWith ( JSON_PAYLOAD_FILE ) ) { String resourceJsonFile = token . substring ( JSON_PAYLOAD_FILE . length ( ) ) ; try { Object jsonFileContent = objectMapper . readTree ( readJsonAsString ( resourceJsonFile ) ) ; entry . setValue ( jsonFileContent ) ; } catch ( Exception exx ) { LOGGER . error ( "External file reference exception - {}" , exx . getMessage ( ) ) ; throw new RuntimeException ( exx ) ; } } // ---------------------------------------------------- // Extension- for XML file type in case a ticket raised // ---------------------------------------------------- /* else if (token != null && token.startsWith(XML_FILE)) { } */ // --------------------------------------------------- // Extension- for Other types in case a ticket raised // --------------------------------------------------- /* else if (token != null && token.startsWith(OTHER_FILE)) { } */ } } } ) ; }
Digs deep into the nested map and looks for external file reference if found replaces the place holder with the file content . This is handy when the engineers wants to drive the common contents from a central place .