Search in sources :

Example 56 with JsonToken

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);
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 57 with JsonToken

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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Schema(org.apache.avro.Schema) JsonToken(com.fasterxml.jackson.core.JsonToken) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 58 with JsonToken

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;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 59 with JsonToken

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);
}
Also used : TableRowResult(com.palantir.atlasdb.api.TableRowResult) RangeToken(com.palantir.atlasdb.api.RangeToken) TableRange(com.palantir.atlasdb.api.TableRange) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 60 with JsonToken

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();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonToken (com.fasterxml.jackson.core.JsonToken)251 IOException (java.io.IOException)65 JsonParser (com.fasterxml.jackson.core.JsonParser)44 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)25 JsonFactory (com.fasterxml.jackson.core.JsonFactory)18 JsonParseException (com.fasterxml.jackson.core.JsonParseException)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 SqlNullable (com.facebook.presto.spi.function.SqlNullable)6 SqlType (com.facebook.presto.spi.function.SqlType)6 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)6 JsonParserHelper.assertExpectedJsonToken (com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken)5 InputStream (java.io.InputStream)5 LinkedHashMap (java.util.LinkedHashMap)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 ByteString (com.google.protobuf.ByteString)4 HashSet (java.util.HashSet)4 MappingJsonFactory (com.fasterxml.jackson.databind.MappingJsonFactory)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3