private boolean moveParserToField ( JsonParser parser , String path ) throws IOException { List < String > segments = getFieldPath ( path ) ; for ( String segment : segments ) { if ( parser . getCurrentToken ( ) != JsonToken . START_OBJECT ) { // Always expect the path to be fields in a JSON map return false ; } boolean found = false ; JsonToken currentToken = parser . nextToken ( ) ; while ( ! found && currentToken != JsonToken . END_OBJECT ) { if ( currentToken != JsonToken . FIELD_NAME ) { // This should always be a field. Something is amiss. throw new IOException ( "Field not found at expected location" ) ; } String fieldName = parser . getText ( ) ; if ( fieldName . equals ( segment ) ) { // Move to the next token, which is the field value found = true ; currentToken = parser . nextToken ( ) ; } else { parser . nextValue ( ) ; currentToken = skipValue ( parser ) ; } } if ( ! found ) { // Field was not found return false ; } } // The current location in the parser is the value. return true ; }
Don t materialize the entire parser content do a targeted search for the value that matches the path .