use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class ExtendedTypeFieldFactory method buildExtendedTypeParser.
private ElementParser buildExtendedTypeParser(FieldDefn fieldDefn) {
// Extended types are objects: { "$type": ... }
// Extended arrays are [ { "$type": ...
TokenIterator tokenizer = fieldDefn.tokenizer();
JsonToken token = tokenizer.requireNext();
ElementParser parser;
switch(token) {
case START_OBJECT:
parser = extendedTypeParserFor(fieldDefn, false);
break;
case START_ARRAY:
parser = arrayParserFor(fieldDefn);
break;
default:
parser = null;
}
tokenizer.unget(token);
return parser;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class NullValueParser method parse.
/**
* Parses nulls. On the first non-null
* Parses <code>true | false | null | integer | float | string|
* embedded-object | { ... } | [ ... ]</code>
*/
@Override
public void parse(TokenIterator tokenizer) {
JsonToken token = tokenizer.requireNext();
if (token != JsonToken.VALUE_NULL) {
tokenizer.unget(token);
resolve(tokenizer).parse(tokenizer);
// This parser never called again
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class JsonStructureParser method recover.
/**
* Attempt recovery from a JSON syntax error by skipping to the next
* record. The Jackson parser is quite limited in its recovery abilities.
*
* @return {@code true} if another record can be read, {@code false}
* if EOF.
* @throws org.apache.drill.common.exceptions.UserException if the error is unrecoverable
* @see <a href="https://issues.apache.org/jira/browse/DRILL-4653">DRILL-4653</a>
* @see <a href="https://issues.apache.org/jira/browse/DRILL-5953">DRILL-5953</a>
*/
private boolean recover() {
logger.warn("Attempting recovery from JSON syntax error. " + tokenizer.context());
boolean firstAttempt = true;
while (true) {
while (true) {
try {
if (tokenizer.getParser().isClosed()) {
throw errorFactory().unrecoverableError();
}
JsonToken token = tokenizer.next();
if (token == null) {
if (firstAttempt && !options().skipMalformedDocument) {
throw errorFactory().unrecoverableError();
}
return false;
}
if (token == JsonToken.NOT_AVAILABLE) {
return false;
}
if (token == JsonToken.END_OBJECT) {
break;
}
firstAttempt = false;
} catch (RecoverableJsonException e) {
// Ignore, keep trying
}
}
try {
JsonToken token = tokenizer.next();
if (token == null || token == JsonToken.NOT_AVAILABLE) {
return false;
}
if (token == JsonToken.START_OBJECT) {
logger.warn("Attempting to resume JSON parse. " + tokenizer.context());
tokenizer.unget(token);
errorRecoveryCount++;
return true;
}
} catch (RecoverableJsonException e) {
// Ignore, keep trying
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project ez-vcard by mangstadt.
the class JCardRawReader method checkCurrent.
private void checkCurrent(JsonToken expected) throws JCardParseException {
JsonToken actual = parser.getCurrentToken();
check(expected, actual);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project presto by prestodb.
the class ProxyResource method rewriteResponse.
private static byte[] rewriteResponse(byte[] input, Function<String, String> uriRewriter) {
try {
JsonParser parser = JSON_FACTORY.createParser(input);
ByteArrayOutputStream out = new ByteArrayOutputStream(input.length * 2);
JsonGenerator generator = JSON_FACTORY.createGenerator(out);
JsonToken token = parser.nextToken();
if (token != START_OBJECT) {
throw invalidJson("bad start token: " + token);
}
generator.copyCurrentEvent(parser);
while (true) {
token = parser.nextToken();
if (token == null) {
throw invalidJson("unexpected end of stream");
}
if (token == END_OBJECT) {
generator.copyCurrentEvent(parser);
break;
}
if (token == FIELD_NAME) {
String name = parser.getValueAsString();
if (!"nextUri".equals(name) && !"partialCancelUri".equals(name)) {
generator.copyCurrentStructure(parser);
continue;
}
token = parser.nextToken();
if (token != VALUE_STRING) {
throw invalidJson(format("bad %s token: %s", name, token));
}
String value = parser.getValueAsString();
value = uriRewriter.apply(value);
generator.writeStringField(name, value);
continue;
}
throw invalidJson("unexpected token: " + token);
}
token = parser.nextToken();
if (token != null) {
throw invalidJson("unexpected token after object close: " + token);
}
generator.close();
return out.toByteArray();
} catch (IOException e) {
throw new ProxyException(e);
}
}
Aggregations