Search in sources :

Example 26 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project vespa by vespa-engine.

the class DocumentParser method handleIdentLevelTwo.

private void handleIdentLevelTwo(DocumentParseInfo documentParseInfo) {
    try {
        JsonToken currentToken = parser.getCurrentToken();
        // "fields" opens a dictionary and is therefore on level two which might be surprising.
        if (currentToken == JsonToken.START_OBJECT && FIELDS.equals(parser.getCurrentName())) {
            documentParseInfo.fieldsBuffer.bufferObject(currentToken, parser);
            processIndent();
        }
    } catch (IOException e) {
        throw new RuntimeException("Got IO exception while parsing document", e);
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException)

Example 27 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project vespa by vespa-engine.

the class DocumentParser method handleIdentLevelOne.

private void handleIdentLevelOne(DocumentParseInfo documentParseInfo, boolean docIdAndOperationIsSetExternally) throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_TRUE || currentToken == JsonToken.VALUE_FALSE) {
        try {
            if (CREATE_IF_NON_EXISTENT.equals(parser.getCurrentName())) {
                documentParseInfo.create = Optional.ofNullable(parser.getBooleanValue());
                return;
            }
        } catch (IOException e) {
            throw new RuntimeException("Got IO exception while parsing document", e);
        }
    }
    if ((currentToken == JsonToken.VALUE_TRUE || currentToken == JsonToken.VALUE_FALSE) && CREATE_IF_NON_EXISTENT.equals(parser.getCurrentName())) {
        documentParseInfo.create = Optional.of(currentToken == JsonToken.VALUE_TRUE);
    } else if (currentToken == JsonToken.VALUE_STRING && CONDITION.equals(parser.getCurrentName())) {
        documentParseInfo.condition = Optional.of(parser.getText());
    } else if (currentToken == JsonToken.VALUE_STRING) {
        // as well.
        if (!docIdAndOperationIsSetExternally) {
            documentParseInfo.operationType = operationNameToOperationType(parser.getCurrentName());
            documentParseInfo.documentId = new DocumentId(parser.getText());
        }
    }
}
Also used : DocumentId(com.yahoo.document.DocumentId) JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException)

Example 28 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project vespa by vespa-engine.

the class TokenBuffer method next.

public JsonToken next() {
    buffer.removeFirst();
    Token t = buffer.peekFirst();
    if (t == null) {
        return null;
    }
    updateNesting(t.token);
    return t.token;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 29 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project vespa by vespa-engine.

the class MapReader method fillMapFromArray.

@SuppressWarnings({ "rawtypes", "cast", "unchecked" })
public static void fillMapFromArray(TokenBuffer buffer, MapFieldValue parent) {
    JsonToken token = buffer.currentToken();
    int initNesting = buffer.nesting();
    expectArrayStart(token);
    token = buffer.next();
    DataType keyType = parent.getDataType().getKeyType();
    DataType valueType = parent.getDataType().getValueType();
    while (buffer.nesting() >= initNesting) {
        FieldValue key = null;
        FieldValue value = null;
        expectObjectStart(token);
        token = buffer.next();
        for (int i = 0; i < 2; ++i) {
            if (MAP_KEY.equals(buffer.currentName())) {
                key = readSingleValue(buffer, keyType);
            } else if (MAP_VALUE.equals(buffer.currentName())) {
                value = readSingleValue(buffer, valueType);
            }
            token = buffer.next();
        }
        Preconditions.checkState(key != null && value != null, "Missing key or value for map entry.");
        parent.put(key, value);
        expectObjectEnd(token);
        // array end or next entry
        token = buffer.next();
    }
}
Also used : DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) CollectionDataType(com.yahoo.document.CollectionDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) MapDataType(com.yahoo.document.MapDataType) JsonToken(com.fasterxml.jackson.core.JsonToken) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

Example 30 with JsonToken

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project vespa by vespa-engine.

the class MapReader method fillMapFromObject.

@SuppressWarnings({ "rawtypes", "cast", "unchecked" })
public static void fillMapFromObject(TokenBuffer buffer, MapFieldValue parent) {
    JsonToken token = buffer.currentToken();
    int initNesting = buffer.nesting();
    expectObjectStart(token);
    token = buffer.next();
    DataType keyType = parent.getDataType().getKeyType();
    DataType valueType = parent.getDataType().getValueType();
    while (buffer.nesting() >= initNesting) {
        FieldValue key = readAtomic(buffer.currentName(), keyType);
        FieldValue value = readSingleValue(buffer, valueType);
        Preconditions.checkState(key != null && value != null, "Missing key or value for map entry.");
        parent.put(key, value);
        token = buffer.next();
    }
    expectObjectEnd(token);
}
Also used : DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) CollectionDataType(com.yahoo.document.CollectionDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) MapDataType(com.yahoo.document.MapDataType) JsonToken(com.fasterxml.jackson.core.JsonToken) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

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