private void skipToField(JsonParser jp, String fieldName, ParseState state) throws JsonParseException, IOException { String lastFieldName = null; while (jp.getCurrentToken() != null) { switch (jp.getCurrentToken()) { case FIELD_NAME: lastFieldName = jp.getCurrentName(); jp.nextToken(); break; case START_OBJECT: if (!state.inRow) { state.inRow = true; jp.nextToken(); } else { if (isInField(fieldName, lastFieldName)) { state.fieldIsNull = false; return; } else { jp.skipChildren(); } } break; default: if (isInField(ID_FIELD_NAME, lastFieldName)) { state.lastId = jp.readValueAsTree().getTextValue(); } else if (isInField(KEY_FIELD_NAME, lastFieldName)) { state.lastKey = jp.readValueAsTree(); } else if (isInField(ERROR_FIELD_NAME, lastFieldName)) { JsonNode error = jp.readValueAsTree(); if (ignoreNotFound && error.asText().equals("not_found")) { lastFieldName = null; state.inRow = false; jp.nextToken(); } else { throw new ViewResultException(state.lastKey, error.asText()); } } else if (isInField(fieldName, lastFieldName)) { if (jp.getCurrentToken() == JsonToken.VALUE_NULL) { state.fieldIsNull = true; } else { state.fieldIsNull = false; } jp.nextToken(); return; } jp.nextToken(); break; } } }
private void skipToField(JsonParser jp, String fieldName, ParseState state) throws JsonParseException, IOException { String lastFieldName = null; while (jp.getCurrentToken() != null) { switch (jp.getCurrentToken()) { case FIELD_NAME: lastFieldName = jp.getCurrentName(); jp.nextToken(); break; case START_OBJECT: if (!state.inRow) { state.inRow = true; jp.nextToken(); } else { if (isInField(fieldName, lastFieldName)) { return; } else { jp.skipChildren(); } } break; default: if (isInField(fieldName, lastFieldName)) { jp.nextToken(); return; } jp.nextToken(); break; } } }
private void endRow(JsonParser jp, ParseState state) throws IOException, JsonParseException { state.inRow = false; jp.nextToken(); }