private void loadJsonResource ( JSONObject json , Properties properties , Object name ) throws JSONException { Iterator < ? > keys = json . keys ( ) ; while ( keys . hasNext ( ) ) { Object obj = keys . next ( ) ; if ( ! ( obj instanceof String ) ) { LOG . warn ( "Object not instance of string : " + obj + " skipping" ) ; continue ; } String key = ( String ) obj ; // can't have . in thrift fields so we represent . with _ String keyUnderscoresToDots = key . replace ( "_" , "." ) ; // actual _ are represented as __ in thrift schema keyUnderscoresToDots = keyUnderscoresToDots . replace ( ".." , "_" ) ; if ( ! json . isNull ( key ) ) { Object value = json . get ( key ) ; String stringVal = "" ; if ( value instanceof String ) { stringVal = ( String ) value ; } else if ( value instanceof Integer ) { stringVal = new Integer ( ( Integer ) value ) . toString ( ) ; } else if ( value instanceof Long ) { stringVal = new Long ( ( Long ) value ) . toString ( ) ; } else if ( value instanceof Double ) { stringVal = new Double ( ( Double ) value ) . toString ( ) ; } else if ( value instanceof Boolean ) { stringVal = new Boolean ( ( Boolean ) value ) . toString ( ) ; } else if ( value instanceof JSONObject ) { loadJsonResource ( ( JSONObject ) value , properties , name ) ; continue ; } else { LOG . warn ( "unsupported value in json object: " + value ) ; } if ( ! finalParameters . contains ( keyUnderscoresToDots ) ) { properties . setProperty ( keyUnderscoresToDots , stringVal ) ; updatingResource . put ( keyUnderscoresToDots , name . toString ( ) ) ; } else { LOG . warn ( name + ":a attempt to override final parameter: " + keyUnderscoresToDots + "; Ignoring." ) ; } } } }
Helper function to loadResource that adds resources to the properties parameter by parsing through a json object .