use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project components by Talend.
the class DatasetWritePayload method readConfiguration.
private static UiSpecsPropertiesDto readConfiguration(JsonParser parser) throws IOException {
JsonToken configFieldToken = parser.nextToken();
isTrue(FIELD_NAME == configFieldToken, invalidInputMessage(FIELD_NAME, configFieldToken));
isTrue(Objects.equals(CONFIGURATION_FIELD_NAME, parser.getText()), invalidInputMessage(CONFIGURATION_FIELD_NAME, parser.getText()));
JsonToken avroSchemaFieldObjectStartToken = parser.nextToken();
isTrue(START_OBJECT == avroSchemaFieldObjectStartToken, invalidInputMessage(START_OBJECT, avroSchemaFieldObjectStartToken));
return parser.readValueAs(UiSpecsPropertiesDto.class);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project components by Talend.
the class DatasetWritePayload method readAvroSchema.
private static Schema readAvroSchema(JsonParser parser) throws IOException {
JsonToken avroSchemaFieldToken = parser.nextToken();
isTrue(FIELD_NAME == avroSchemaFieldToken, invalidInputMessage(FIELD_NAME, avroSchemaFieldToken));
isTrue(Objects.equals(AVRO_SCHEMA_FIELD_NAME, parser.getText()), invalidInputMessage(AVRO_SCHEMA_FIELD_NAME, parser.getText()));
JsonToken configFieldObjectStartToken = parser.nextToken();
isTrue(START_OBJECT == configFieldObjectStartToken, invalidInputMessage(START_OBJECT, configFieldObjectStartToken));
// This code is so awful I will certainly have cancer
ObjectNode schemaAsJson = parser.readValueAsTree();
Schema.Parser avroSchemaParser = new Schema.Parser();
return avroSchemaParser.parse(new ObjectMapper().writeValueAsString(schemaAsJson));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project components by Talend.
the class EntityParser method rewindToField.
/**
* Rewinds {@link JsonParser} to the value of specified field
*
* @param parser JSON parser
* @param fieldName name of field rewind to
* @return true if field was found, false otherwise
* @throws IOException in case of exception during JSON parsing
*/
private static boolean rewindToField(JsonParser parser, final String fieldName) throws IOException {
JsonToken currentToken = parser.nextToken();
/*
* There is no special token, which denotes end of file, in Jackson.
* This counter is used to define the end of file.
* The counter counts '{' and '}'. It is increased, when meets '{' and
* decreased, when meets '}'. When braceCounter == 0 it means the end
* of file was met
*/
int braceCounter = 0;
String currentField = null;
do {
if (JsonToken.START_OBJECT == currentToken) {
braceCounter++;
}
if (JsonToken.END_OBJECT == currentToken) {
braceCounter--;
}
if (JsonToken.FIELD_NAME == currentToken) {
currentField = parser.getCurrentName();
}
currentToken = parser.nextToken();
} while (!fieldName.equals(currentField) && braceCounter != END_JSON);
return braceCounter != END_JSON;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project atlasdb by palantir.
the class RangeTokenDeserializer method deserialize.
@Override
public RangeToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonToken jsonToken = jp.getCurrentToken();
if (jsonToken == JsonToken.START_OBJECT) {
jsonToken = jp.nextToken();
}
TableRowResult results = null;
TableRange nextRange = null;
for (; jsonToken == JsonToken.FIELD_NAME; jsonToken = jp.nextToken()) {
String fieldName = jp.getCurrentName();
jsonToken = jp.nextToken();
if (fieldName.equals("data")) {
results = jp.readValueAs(TableRowResult.class);
} else if (fieldName.equals("next")) {
nextRange = jp.readValueAs(TableRange.class);
}
}
return new RangeToken(results, nextRange);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project jackson-core by FasterXML.
the class ParserErrorHandlingTest method _testMangledNumbersFloat.
private void _testMangledNumbersFloat(int mode) throws Exception {
// Also test with floats
JsonParser p = createParser(mode, "1.5false");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
}
Aggregations