Search in sources :

Example 76 with JsonToken

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

the class Bean81RBindMap method parseOnJacksonAsString.

/**
 * parse with jackson
 */
@Override
public Bean81R parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
    Bean81R instance = new Bean81R();
    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 "valueByteArray":
                // field valueByteArray (mapped with "valueByteArray")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.valueByteArray = Base64Utils.decode(jacksonParser.getValueAsString());
                }
                break;
            case "id":
                // field id (mapped with "id")
                instance.id = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "valueMapStringInteger":
                // field valueMapStringInteger (mapped with "valueMapStringInteger")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    HashMap<String, Integer> collection = new HashMap<>();
                    String key = null;
                    Integer 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.VALUE_NULL) {
                                            value = PrimitiveUtils.readInteger(jacksonParser.getText(), null);
                                        }
                                    }
                                    break;
                            }
                        }
                        collection.put(key, value);
                        key = null;
                        value = null;
                        jacksonParser.nextToken();
                    }
                    instance.valueMapStringInteger = collection;
                }
                break;
            case "valueInteger":
                // field valueInteger (mapped with "valueInteger")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.valueInteger = PrimitiveUtils.readInteger(jacksonParser.getText(), null);
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : HashMap(java.util.HashMap) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 77 with JsonToken

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

the class Bean81SBindMap method parseOnJacksonAsString.

/**
 * parse with jackson
 */
@Override
public Bean81S parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
    Bean81S instance = new Bean81S();
    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 "id":
                // field id (mapped with "id")
                instance.id = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "valueByteArray":
                // field valueByteArray (mapped with "valueByteArray")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.valueByteArray = Base64Utils.decode(jacksonParser.getValueAsString());
                }
                break;
            case "valueMapStringInteger":
                // field valueMapStringInteger (mapped with "valueMapStringInteger")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    HashMap<String, Integer> collection = new HashMap<>();
                    String key = null;
                    Integer 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.VALUE_NULL) {
                                            value = PrimitiveUtils.readInteger(jacksonParser.getText(), null);
                                        }
                                    }
                                    break;
                            }
                        }
                        collection.put(key, value);
                        key = null;
                        value = null;
                        jacksonParser.nextToken();
                    }
                    instance.valueMapStringInteger = collection;
                }
                break;
            case "valueInteger":
                // field valueInteger (mapped with "valueInteger")
                if (jacksonParser.currentToken() != JsonToken.VALUE_NULL) {
                    instance.valueInteger = PrimitiveUtils.readInteger(jacksonParser.getText(), null);
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : HashMap(java.util.HashMap) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 78 with JsonToken

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

the class Bean81VBindMap method parseOnJacksonAsString.

/**
 * parse with jackson
 */
@Override
public Bean81V parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
    Bean81V instance = new Bean81V();
    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 "id":
                // field id (mapped with "id")
                instance.id = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "array":
                // field valueByteArray (mapped with "array")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<Byte> collection = new ArrayList<>();
                    Byte 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.readByte(jacksonParser.getText(), null);
                        }
                        collection.add(item);
                    }
                    instance.valueByteArray = CollectionUtils.asByteArray(collection);
                } else if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && !StringUtils.hasText(jacksonParser.getValueAsString())) {
                    ArrayList<Byte> collection = new ArrayList<>();
                    instance.valueByteArray = CollectionUtils.asByteArray(collection);
                }
                break;
            case "list":
                // field valueIntegerList (mapped with "list")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<Integer> collection = new ArrayList<>();
                    Integer 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.readInteger(jacksonParser.getText(), null);
                        }
                        collection.add(item);
                    }
                    instance.valueIntegerList = collection;
                } else if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && !StringUtils.hasText(jacksonParser.getValueAsString())) {
                    ArrayList<Integer> collection = new ArrayList<>();
                    instance.valueIntegerList = collection;
                }
                break;
            case "map":
                // field valueMapStringInteger (mapped with "map")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    HashMap<String, Integer> collection = new HashMap<>();
                    String key = null;
                    Integer 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.VALUE_NULL) {
                                            value = PrimitiveUtils.readInteger(jacksonParser.getText(), null);
                                        }
                                    }
                                    break;
                            }
                        }
                        collection.put(key, value);
                        key = null;
                        value = null;
                        jacksonParser.nextToken();
                    }
                    instance.valueMapStringInteger = collection;
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 79 with JsonToken

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

the class Bean81V4BindMap method parseOnJacksonAsString.

/**
 * parse with jackson
 */
@Override
public Bean81V4 parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
    Bean81V4 instance = new Bean81V4();
    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 "id":
                // field id (mapped with "id")
                instance.id = PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
                break;
            case "valueByteArray":
                // field valueByteArray (mapped with "valueByteArray")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<Byte> collection = new ArrayList<>();
                    Byte 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.readByte(jacksonParser.getText(), null);
                        }
                        collection.add(item);
                    }
                    instance.valueByteArray = CollectionUtils.asByteArray(collection);
                } else if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && !StringUtils.hasText(jacksonParser.getValueAsString())) {
                    ArrayList<Byte> collection = new ArrayList<>();
                    instance.valueByteArray = CollectionUtils.asByteArray(collection);
                }
                break;
            case "valueIntegerList":
                // field valueIntegerList (mapped with "valueIntegerList")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<Integer> collection = new ArrayList<>();
                    Integer 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.readInteger(jacksonParser.getText(), null);
                        }
                        collection.add(item);
                    }
                    instance.valueIntegerList = collection;
                } else if (jacksonParser.currentToken() == JsonToken.VALUE_STRING && !StringUtils.hasText(jacksonParser.getValueAsString())) {
                    ArrayList<Integer> collection = new ArrayList<>();
                    instance.valueIntegerList = collection;
                }
                break;
            case "valueMapStringInteger":
                // field valueMapStringInteger (mapped with "valueMapStringInteger")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    HashMap<String, Integer> collection = new HashMap<>();
                    String key = null;
                    Integer 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.VALUE_NULL) {
                                            value = PrimitiveUtils.readInteger(jacksonParser.getText(), null);
                                        }
                                    }
                                    break;
                            }
                        }
                        collection.put(key, value);
                        key = null;
                        value = null;
                        jacksonParser.nextToken();
                    }
                    instance.valueMapStringInteger = collection;
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 80 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)

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