Search in sources :

Example 81 with JsonToken

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

the class Bean84ABindMap method parseOnJacksonAsString.

/**
 * parse with jackson
 */
@Override
public Bean84A parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
    Bean84A instance = new Bean84A();
    String fieldName;
    if (jacksonParser.getCurrentToken() == null) {
        jacksonParser.nextToken();
    }
    if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        jacksonParser.skipChildren();
        return instance;
    }
    while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
        fieldName = jacksonParser.getCurrentName();
        jacksonParser.nextToken();
        // Parse fields:
        switch(fieldName) {
            case "columnArrayByteType":
                // field columnArrayByteType (mapped with "columnArrayByteType")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.columnArrayByteType = Base64Utils.decode(jacksonParser.getValueAsString());
                }
                break;
            case "columnArrayChar":
                // field columnArrayChar (mapped with "columnArrayChar")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<Character> collection = new ArrayList<>();
                    Character item = null;
                    String tempValue = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        tempValue = jacksonParser.getValueAsString();
                        if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                            item = null;
                        } else {
                            item = PrimitiveUtils.readCharacter(jacksonParser.getText(), null);
                        }
                        collection.add(item);
                    }
                    instance.columnArrayChar = CollectionUtils.asCharacterArray(collection);
                } else if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && !StringUtils.hasText(jacksonParser.getValueAsString())) {
                    ArrayList<Character> collection = new ArrayList<>();
                    instance.columnArrayChar = CollectionUtils.asCharacterArray(collection);
                }
                break;
            case "columnArrayCharType":
                // field columnArrayCharType (mapped with "columnArrayCharType")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<Character> collection = new ArrayList<>();
                    Character item = null;
                    String tempValue = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        tempValue = jacksonParser.getValueAsString();
                        if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                            item = null;
                        } else {
                            item = PrimitiveUtils.readCharacter(jacksonParser.getText(), '');
                        }
                        collection.add(item);
                    }
                    instance.columnArrayCharType = CollectionUtils.asCharacterTypeArray(collection);
                } else if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && !StringUtils.hasText(jacksonParser.getValueAsString())) {
                    ArrayList<Character> collection = new ArrayList<>();
                    instance.columnArrayCharType = CollectionUtils.asCharacterTypeArray(collection);
                }
                break;
            case "columnBean":
                // field columnBean (mapped with "columnBean")
                if (jacksonParser.currentToken() == JsonToken.START_OBJECT || jacksonParser.currentToken() == JsonToken.VALUE_STRING) {
                    instance.columnBean = bean84ABindMap.parseOnJacksonAsString(jacksonParser);
                }
                break;
            case "columnListString":
                // field columnListString (mapped with "columnListString")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<String> collection = new ArrayList<>();
                    String item = null;
                    String tempValue = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        tempValue = jacksonParser.getValueAsString();
                        if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                            item = null;
                        } else {
                            if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                                item = jacksonParser.getText();
                            }
                        }
                        collection.add(item);
                    }
                    instance.columnListString = collection;
                } else if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && !StringUtils.hasText(jacksonParser.getValueAsString())) {
                    ArrayList<String> collection = new ArrayList<>();
                    instance.columnListString = collection;
                }
                break;
            case "columnMapIntegerString":
                // field columnMapIntegerString (mapped with "columnMapIntegerString")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    HashMap<Integer, String> collection = new HashMap<>();
                    Integer key = null;
                    String value = null;
                    JsonToken current;
                    String tempValue = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        current = jacksonParser.currentToken();
                        for (int i = 0; i < 2; i++) {
                            while (current != JsonToken.FIELD_NAME) {
                                current = jacksonParser.nextToken();
                            }
                            jacksonParser.nextValue();
                            switch(jacksonParser.getCurrentName()) {
                                case "key":
                                    key = PrimitiveUtils.readInteger(jacksonParser.getText(), null);
                                    break;
                                case "value":
                                    tempValue = jacksonParser.getValueAsString();
                                    if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                                        value = null;
                                    } else {
                                        if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                                            value = jacksonParser.getText();
                                        }
                                    }
                                    break;
                            }
                        }
                        collection.put(key, value);
                        key = null;
                        value = null;
                        jacksonParser.nextToken();
                    }
                    instance.columnMapIntegerString = collection;
                }
                break;
            case "id":
                // field id (mapped with "id")
                instance.id = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "param1":
                // field param1 (mapped with "param1")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.param1 = jacksonParser.getText();
                }
                break;
            case "param2":
                // field param2 (mapped with "param2")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.param2 = jacksonParser.getText();
                }
                break;
            case "param3":
                // field param3 (mapped with "param3")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.param3 = jacksonParser.getText();
                }
                break;
            case "param4":
                // field param4 (mapped with "param4")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.param4 = jacksonParser.getText();
                }
                break;
            case "valueString":
                // field valueString (mapped with "valueString")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.valueString = jacksonParser.getText();
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 82 with JsonToken

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

the class ChannelListResponseBindMap method parseOnJacksonAsString.

/**
 * parse with jackson
 */
@Override
public ChannelListResponse parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
    ChannelListResponse instance = new ChannelListResponse();
    String fieldName;
    if (jacksonParser.getCurrentToken() == null) {
        jacksonParser.nextToken();
    }
    if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        jacksonParser.skipChildren();
        return instance;
    }
    while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
        fieldName = jacksonParser.getCurrentName();
        jacksonParser.nextToken();
        // Parse fields:
        switch(fieldName) {
            case "bean":
                // field bean (mapped with "bean")
                if (jacksonParser.currentToken() == JsonToken.START_OBJECT || jacksonParser.currentToken() == JsonToken.VALUE_STRING) {
                    instance.bean = channelBindMap.parseOnJacksonAsString(jacksonParser);
                }
                break;
            case "detailMessage":
                // field detailMessage (mapped with "detailMessage")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.setDetailMessage(jacksonParser.getText());
                }
                break;
            case "list":
                // field list (mapped with "list")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<Channel> collection = new ArrayList<>();
                    Channel item = null;
                    String tempValue = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        tempValue = jacksonParser.getValueAsString();
                        if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                            item = null;
                        } else {
                            item = channelBindMap.parseOnJacksonAsString(jacksonParser);
                        }
                        collection.add(item);
                    }
                    instance.setList(collection);
                } else if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && !StringUtils.hasText(jacksonParser.getValueAsString())) {
                    ArrayList<Channel> collection = new ArrayList<>();
                    instance.setList(collection);
                }
                break;
            case "map":
                // field map (mapped with "map")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    HashMap<String, Channel> collection = new HashMap<>();
                    String key = null;
                    Channel value = null;
                    JsonToken current;
                    String tempValue = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        current = jacksonParser.currentToken();
                        for (int i = 0; i < 2; i++) {
                            while (current != JsonToken.FIELD_NAME) {
                                current = jacksonParser.nextToken();
                            }
                            jacksonParser.nextValue();
                            switch(jacksonParser.getCurrentName()) {
                                case "key":
                                    if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                                        key = jacksonParser.getText();
                                    }
                                    break;
                                case "value":
                                    tempValue = jacksonParser.getValueAsString();
                                    if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                                        value = null;
                                    } else {
                                        if (jacksonParser.currentToken() == JsonToken.START_OBJECT || jacksonParser.currentToken() == JsonToken.VALUE_STRING) {
                                            value = channelBindMap.parseOnJacksonAsString(jacksonParser);
                                        }
                                    }
                                    break;
                            }
                        }
                        collection.put(key, value);
                        key = null;
                        value = null;
                        jacksonParser.nextToken();
                    }
                    instance.map = collection;
                }
                break;
            case "status":
                // field status (mapped with "status")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    String tempEnum = jacksonParser.getText();
                    instance.setStatus(StringUtils.hasText(tempEnum) ? ServiceStatusType.valueOf(tempEnum) : null);
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 83 with JsonToken

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

the class CountryBindMap method parseOnJacksonAsString.

/**
 * parse with jackson
 */
@Override
public Country parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
    Country instance = new Country();
    String fieldName;
    if (jacksonParser.getCurrentToken() == null) {
        jacksonParser.nextToken();
    }
    if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        jacksonParser.skipChildren();
        return instance;
    }
    while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
        fieldName = jacksonParser.getCurrentName();
        jacksonParser.nextToken();
        // Parse fields:
        switch(fieldName) {
            case "area":
                // field area (mapped with "area")
                instance.area = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "callingCode":
                // field callingCode (mapped with "callingCode")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.callingCode = jacksonParser.getText();
                }
                break;
            case "code":
                // field code (mapped with "code")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.code = jacksonParser.getText();
                }
                break;
            case "id":
                // field id (mapped with "id")
                instance.id = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "name":
                // field name (mapped with "name")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.name = jacksonParser.getText();
                }
                break;
            case "region":
                // field region (mapped with "region")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.region = jacksonParser.getText();
                }
                break;
            case "translatedName":
                // field translatedName (mapped with "translatedName")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    HashMap<Translation, String> collection = new HashMap<>();
                    Translation key = null;
                    String value = null;
                    JsonToken current;
                    String tempValue = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        current = jacksonParser.currentToken();
                        for (int i = 0; i < 2; i++) {
                            while (current != JsonToken.FIELD_NAME) {
                                current = jacksonParser.nextToken();
                            }
                            jacksonParser.nextValue();
                            switch(jacksonParser.getCurrentName()) {
                                case "key":
                                    {
                                        String tempEnum = jacksonParser.getText();
                                        key = StringUtils.hasText(tempEnum) ? Translation.valueOf(tempEnum) : null;
                                    }
                                    break;
                                case "value":
                                    tempValue = jacksonParser.getValueAsString();
                                    if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                                        value = null;
                                    } else {
                                        if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                                            value = jacksonParser.getText();
                                        }
                                    }
                                    break;
                            }
                        }
                        collection.put(key, value);
                        key = null;
                        value = null;
                        jacksonParser.nextToken();
                    }
                    instance.translatedName = collection;
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : HashMap(java.util.HashMap) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 84 with JsonToken

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

the class CountryBindMap method parseOnJacksonAsString.

/**
 * parse with jackson
 */
@Override
public Country parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
    Country instance = new Country();
    String fieldName;
    if (jacksonParser.getCurrentToken() == null) {
        jacksonParser.nextToken();
    }
    if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        jacksonParser.skipChildren();
        return instance;
    }
    while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
        fieldName = jacksonParser.getCurrentName();
        jacksonParser.nextToken();
        // Parse fields:
        switch(fieldName) {
            case "area":
                // field area (mapped with "area")
                instance.area = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "callingCode":
                // field callingCode (mapped with "callingCode")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.callingCode = jacksonParser.getText();
                }
                break;
            case "code":
                // field code (mapped with "code")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.code = jacksonParser.getText();
                }
                break;
            case "id":
                // field id (mapped with "id")
                instance.id = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "name":
                // field name (mapped with "name")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.name = jacksonParser.getText();
                }
                break;
            case "region":
                // field region (mapped with "region")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.region = jacksonParser.getText();
                }
                break;
            case "translatedName":
                // field translatedName (mapped with "translatedName")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    HashMap<Translation, String> collection = new HashMap<>();
                    Translation key = null;
                    String value = null;
                    JsonToken current;
                    String tempValue = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        current = jacksonParser.currentToken();
                        for (int i = 0; i < 2; i++) {
                            while (current != JsonToken.FIELD_NAME) {
                                current = jacksonParser.nextToken();
                            }
                            jacksonParser.nextValue();
                            switch(jacksonParser.getCurrentName()) {
                                case "key":
                                    {
                                        String tempEnum = jacksonParser.getText();
                                        key = StringUtils.hasText(tempEnum) ? Translation.valueOf(tempEnum) : null;
                                    }
                                    break;
                                case "value":
                                    tempValue = jacksonParser.getValueAsString();
                                    if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                                        value = null;
                                    } else {
                                        if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                                            value = jacksonParser.getText();
                                        }
                                    }
                                    break;
                            }
                        }
                        collection.put(key, value);
                        key = null;
                        value = null;
                        jacksonParser.nextToken();
                    }
                    instance.translatedName = collection;
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : HashMap(java.util.HashMap) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 85 with JsonToken

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

the class VectorOutput method innerRun.

protected boolean innerRun() throws IOException {
    JsonToken t = parser.nextToken();
    if (t != JsonToken.FIELD_NAME) {
        return false;
    }
    String possibleTypeName = parser.getText();
    if (!possibleTypeName.isEmpty() && possibleTypeName.charAt(0) == '$') {
        switch(possibleTypeName) {
            case ExtendedTypeName.BINARY:
                writeBinary(checkNextToken(JsonToken.VALUE_STRING));
                checkCurrentToken(JsonToken.END_OBJECT);
                return true;
            case ExtendedTypeName.TYPE:
                if (checkNextToken(JsonToken.VALUE_NUMBER_INT) || !hasBinary()) {
                    throw UserException.parseError().message("Either $type is not an integer or has no $binary").build(logger);
                }
                writeBinary(checkNextToken(JsonToken.VALUE_STRING));
                checkCurrentToken(JsonToken.END_OBJECT);
                return true;
            case ExtendedTypeName.DATE:
                writeDate(checkNextToken(JsonToken.VALUE_STRING));
                checkNextToken(JsonToken.END_OBJECT);
                return true;
            case ExtendedTypeName.TIME:
                writeTime(checkNextToken(JsonToken.VALUE_STRING));
                checkNextToken(JsonToken.END_OBJECT);
                return true;
            case ExtendedTypeName.TIMESTAMP:
                writeTimestamp(checkNextToken(JsonToken.VALUE_STRING, JsonToken.VALUE_NUMBER_INT));
                checkNextToken(JsonToken.END_OBJECT);
                return true;
            case ExtendedTypeName.INTERVAL:
                writeInterval(checkNextToken(JsonToken.VALUE_STRING));
                checkNextToken(JsonToken.END_OBJECT);
                return true;
            case ExtendedTypeName.INTEGER:
                writeInteger(checkNextToken(JsonToken.VALUE_STRING, JsonToken.VALUE_NUMBER_INT));
                checkNextToken(JsonToken.END_OBJECT);
                return true;
            case ExtendedTypeName.DECIMAL:
                writeDecimal(checkNextToken(JsonToken.VALUE_NUMBER_FLOAT, JsonToken.VALUE_NUMBER_INT));
                checkNextToken(JsonToken.END_OBJECT);
                return true;
        }
    }
    return false;
}
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