public void readToken ( String parentFieldName , JsonToken expectedToken ) throws IOException { JsonToken currentToken = jsonParser . nextToken ( ) ; if ( currentToken != expectedToken ) { throw new IOException ( "Expected a " + expectedToken . toString ( ) + " token when reading the value of the field: " + parentFieldName + " but found a " + currentToken . toString ( ) + " token" ) ; } }
This is a helper method that reads a JSON token using a JsonParser instance and throws an exception if the next token is not the same as the token we expect .