Search in sources :

Example 6 with JsonToken

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

the class JSONFormatter method getList.

private PdxListHelper getList(JsonParser jp, states currentState, PdxListHelper currentPdxList) throws JsonParseException, IOException {
    String currentFieldName = null;
    currentPdxList = new PdxListHelper(currentPdxList, null);
    while (true) {
        JsonToken nt = jp.nextToken();
        if (nt == null) {
            return currentPdxList;
        }
        switch(nt) {
            case START_OBJECT:
                {
                    objectStarts(currentState);
                    currentState = states.OBJECT_START;
                    // need to create new PdxInstance
                    // root object will not name, so create classname lazily from all members.
                    // child object will have name; but create this as well lazily from all members
                    JSONToPdxMapper tmp = getPdxInstance(jp, currentState, null);
                    currentPdxList.addObjectField(currentFieldName, tmp);
                    currentState = states.OBJECT_ENDS;
                    break;
                }
            case END_OBJECT:
                {
                    // pdxinstnce ends
                    throw new IllegalStateException("getList got token END_OBJECT while current state is " + currentState);
                }
            case FIELD_NAME:
                {
                    throw new IllegalStateException("getList got token FIELD_NAME while current state is " + currentState);
                }
            case NOT_AVAILABLE:
                {
                    throw new IllegalStateException("NOT_AVAILABLE token found in getList current state is " + currentState);
                // break;
                }
            case START_ARRAY:
                {
                    // need to create array; fieldname may be there; will it case it not there
                    arrayStarts(currentState);
                    PdxListHelper tmp = currentPdxList.addListField();
                    currentPdxList = tmp;
                    currentState = states.LIST_FOUND;
                    break;
                }
            case END_ARRAY:
                {
                    // array is end
                    arrayEnds(currentState);
                    currentState = states.LIST_ENDS;
                    if (currentPdxList.getParent() == null) {
                        return currentPdxList;
                    }
                    currentPdxList = currentPdxList.getParent();
                    break;
                }
            case VALUE_EMBEDDED_OBJECT:
                {
                    throw new IllegalStateException("VALUE_EMBEDDED_OBJECT token found");
                }
            case VALUE_FALSE:
                {
                    // write boolen
                    boolFound(currentState);
                    currentState = states.SCALAR_FOUND;
                    currentPdxList.addBooleanField(jp.getBooleanValue());
                    break;
                }
            case VALUE_NULL:
                {
                    // write null
                    nullFound(currentState);
                    currentState = states.SCALAR_FOUND;
                    currentPdxList.addNullField(null);
                    break;
                }
            case VALUE_NUMBER_FLOAT:
                {
                    // write double/float
                    doubleFound(currentState);
                    currentState = states.SCALAR_FOUND;
                    // currentPdxList.addDoubleField(jp.getDoubleValue());
                    setNumberField(jp, currentPdxList);
                    break;
                }
            case VALUE_NUMBER_INT:
                {
                    // write int
                    intFound(currentState);
                    currentState = states.SCALAR_FOUND;
                    // currentPdxList.addIntField(jp.getIntValue());
                    setNumberField(jp, currentPdxList);
                    break;
                }
            case VALUE_STRING:
                {
                    // write string
                    stringFound(currentState);
                    currentState = states.SCALAR_FOUND;
                    currentPdxList.addStringField(jp.getText());
                    currentFieldName = null;
                    break;
                }
            case VALUE_TRUE:
                {
                    // write bool
                    boolFound(currentState);
                    currentState = states.SCALAR_FOUND;
                    currentPdxList.addBooleanField(jp.getBooleanValue());
                    break;
                }
            default:
                {
                    throw new IllegalStateException("Token not handled in getlist" + nt);
                }
        }
    }
}
Also used : PdxListHelper(org.apache.geode.pdx.internal.json.PdxListHelper) JSONToPdxMapper(org.apache.geode.pdx.internal.json.JSONToPdxMapper) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 7 with JsonToken

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

the class ActionsJsonDeserializer method processReplaceAllJsonToken.

protected ReplaceAll processReplaceAllJsonToken(JsonParser jsonToken) throws IOException {
    ReplaceAll action = new ReplaceAll();
    if (JsonToken.END_ARRAY.equals(jsonToken.currentToken()) || JsonToken.END_OBJECT.equals(jsonToken.currentToken())) {
        return action;
    }
    JsonToken nextToken = null;
    do {
        if (JsonToken.START_OBJECT.equals(jsonToken.currentToken())) {
            jsonToken.nextToken();
        }
        switch(jsonToken.getCurrentName()) {
            case ActionsJsonSerializer.MATCH:
                jsonToken.nextToken();
                action.setMatch(jsonToken.getValueAsString());
                break;
            case ActionsJsonSerializer.NEW_STRING:
                jsonToken.nextToken();
                action.setNewString(jsonToken.getValueAsString());
                break;
            default:
                break;
        }
        nextToken = jsonToken.nextToken();
    } while (!JsonToken.END_ARRAY.equals(nextToken) && !JsonToken.END_OBJECT.equals(nextToken));
    return action;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 8 with JsonToken

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

the class ActionsJsonDeserializer method processConcatenateJsonToken.

protected Concatenate processConcatenateJsonToken(JsonParser jsonToken) throws IOException {
    Concatenate action = new Concatenate();
    if (JsonToken.END_ARRAY.equals(jsonToken.currentToken()) || JsonToken.END_OBJECT.equals(jsonToken.currentToken())) {
        return action;
    }
    JsonToken nextToken = null;
    do {
        if (JsonToken.START_OBJECT.equals(jsonToken.currentToken())) {
            jsonToken.nextToken();
        }
        switch(jsonToken.getCurrentName()) {
            case ActionsJsonSerializer.DELIMITER:
                jsonToken.nextToken();
                action.setDelimiter(jsonToken.getValueAsString());
                break;
            default:
                break;
        }
        nextToken = jsonToken.nextToken();
    } while (!JsonToken.END_ARRAY.equals(nextToken) && !JsonToken.END_OBJECT.equals(nextToken));
    return action;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 9 with JsonToken

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

the class ActionsJsonDeserializer method processSubStringJsonToken.

protected SubString processSubStringJsonToken(JsonParser jsonToken) throws IOException {
    SubString action = new SubString();
    if (JsonToken.END_ARRAY.equals(jsonToken.currentToken()) || JsonToken.END_OBJECT.equals(jsonToken.currentToken())) {
        return action;
    }
    JsonToken nextToken = null;
    do {
        if (JsonToken.START_OBJECT.equals(jsonToken.currentToken())) {
            jsonToken.nextToken();
        }
        switch(jsonToken.getCurrentName()) {
            case ActionsJsonSerializer.START_INDEX:
                jsonToken.nextToken();
                action.setStartIndex(jsonToken.getIntValue());
                break;
            case ActionsJsonSerializer.END_INDEX:
                jsonToken.nextToken();
                action.setEndIndex(jsonToken.getIntValue());
                break;
            default:
                break;
        }
        nextToken = jsonToken.nextToken();
    } while (!JsonToken.END_ARRAY.equals(nextToken) && !JsonToken.END_OBJECT.equals(nextToken));
    return action;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 10 with JsonToken

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

the class ActionsJsonDeserializer method processConvertAreaUnitJsonToken.

protected ConvertAreaUnit processConvertAreaUnitJsonToken(JsonParser jsonToken) throws IOException {
    ConvertAreaUnit action = new ConvertAreaUnit();
    if (JsonToken.END_ARRAY.equals(jsonToken.currentToken()) || JsonToken.END_OBJECT.equals(jsonToken.currentToken())) {
        return action;
    }
    JsonToken nextToken = null;
    do {
        if (JsonToken.START_OBJECT.equals(jsonToken.currentToken())) {
            jsonToken.nextToken();
        }
        switch(jsonToken.getCurrentName()) {
            case ActionsJsonSerializer.FROM_UNIT:
                jsonToken.nextToken();
                action.setFromUnit(AreaUnitType.fromValue(jsonToken.getValueAsString()));
                break;
            case ActionsJsonSerializer.TO_UNIT:
                jsonToken.nextToken();
                action.setToUnit(AreaUnitType.fromValue(jsonToken.getValueAsString()));
                break;
            default:
                break;
        }
        nextToken = jsonToken.nextToken();
    } while (!JsonToken.END_ARRAY.equals(nextToken) && !JsonToken.END_OBJECT.equals(nextToken));
    return action;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

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