Search in sources :

Example 96 with JsonParser

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

the class ByteBeanTable method parseValue2.

/**
 * for attribute value2 parsing
 */
public static Byte[] parseValue2(byte[] input) {
    if (input == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (JacksonWrapperParser wrapper = context.createParser(input)) {
        JsonParser jacksonParser = wrapper.jacksonParser;
        // START_OBJECT
        jacksonParser.nextToken();
        // value of "element"
        jacksonParser.nextValue();
        Byte[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<Byte> collection = new ArrayList<>();
            Byte item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = jacksonParser.getByteValue();
                }
                collection.add(item);
            }
            result = CollectionUtils.asByteArray(collection);
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : ArrayList(java.util.ArrayList) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) KriptonJsonContext(com.abubusoft.kripton.KriptonJsonContext) JacksonWrapperParser(com.abubusoft.kripton.persistence.JacksonWrapperParser) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 97 with JsonParser

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

the class ByteDaoImpl method parser1.

/**
 * for param parser1 parsing
 */
private Byte[] parser1(byte[] input) {
    if (input == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (JacksonWrapperParser wrapper = context.createParser(input)) {
        JsonParser jacksonParser = wrapper.jacksonParser;
        // START_OBJECT
        jacksonParser.nextToken();
        // value of "element"
        jacksonParser.nextValue();
        Byte[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<Byte> collection = new ArrayList<>();
            Byte item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = jacksonParser.getByteValue();
                }
                collection.add(item);
            }
            result = CollectionUtils.asByteArray(collection);
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : ArrayList(java.util.ArrayList) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) KriptonJsonContext(com.abubusoft.kripton.KriptonJsonContext) JacksonWrapperParser(com.abubusoft.kripton.persistence.JacksonWrapperParser) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 98 with JsonParser

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

the class CharBeanTable method parseValue.

/**
 * for attribute value parsing
 */
public static char[] parseValue(byte[] input) {
    if (input == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (JacksonWrapperParser wrapper = context.createParser(input)) {
        JsonParser jacksonParser = wrapper.jacksonParser;
        // START_OBJECT
        jacksonParser.nextToken();
        // value of "element"
        jacksonParser.nextValue();
        char[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<Character> collection = new ArrayList<>();
            Character item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = Character.valueOf((char) jacksonParser.getIntValue());
                }
                collection.add(item);
            }
            result = CollectionUtils.asCharacterTypeArray(collection);
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : ArrayList(java.util.ArrayList) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) KriptonJsonContext(com.abubusoft.kripton.KriptonJsonContext) JacksonWrapperParser(com.abubusoft.kripton.persistence.JacksonWrapperParser) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 99 with JsonParser

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

the class CharBeanTable method parseValue2.

/**
 * for attribute value2 parsing
 */
public static Character[] parseValue2(byte[] input) {
    if (input == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (JacksonWrapperParser wrapper = context.createParser(input)) {
        JsonParser jacksonParser = wrapper.jacksonParser;
        // START_OBJECT
        jacksonParser.nextToken();
        // value of "element"
        jacksonParser.nextValue();
        Character[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<Character> collection = new ArrayList<>();
            Character item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = Character.valueOf((char) jacksonParser.getIntValue());
                }
                collection.add(item);
            }
            result = CollectionUtils.asCharacterArray(collection);
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : ArrayList(java.util.ArrayList) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) KriptonJsonContext(com.abubusoft.kripton.KriptonJsonContext) JacksonWrapperParser(com.abubusoft.kripton.persistence.JacksonWrapperParser) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 100 with JsonParser

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

the class BeanDaoImpl method parser5.

/**
 * for param parser5 parsing
 */
private Set<String> parser5(byte[] input) {
    if (input == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (JacksonWrapperParser wrapper = context.createParser(input)) {
        JsonParser jacksonParser = wrapper.jacksonParser;
        // START_OBJECT
        jacksonParser.nextToken();
        // value of "element"
        jacksonParser.nextValue();
        Set<String> result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            HashSet<String> collection = new HashSet<>();
            String item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = jacksonParser.getText();
                }
                collection.add(item);
            }
            result = collection;
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) KriptonJsonContext(com.abubusoft.kripton.KriptonJsonContext) JacksonWrapperParser(com.abubusoft.kripton.persistence.JacksonWrapperParser) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) JsonParser(com.fasterxml.jackson.core.JsonParser) HashSet(java.util.HashSet)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)587 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)258 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)258 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 ArrayList (java.util.ArrayList)171 IOException (java.io.IOException)126 JsonFactory (com.fasterxml.jackson.core.JsonFactory)76 Test (org.junit.Test)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)51 JsonNode (com.fasterxml.jackson.databind.JsonNode)46 HashSet (java.util.HashSet)43 JsonToken (com.fasterxml.jackson.core.JsonToken)41 LinkedHashSet (java.util.LinkedHashSet)39 HashMap (java.util.HashMap)35 LinkedList (java.util.LinkedList)26 JsonParseException (com.fasterxml.jackson.core.JsonParseException)23 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)21 List (java.util.List)21 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)20 InputStream (java.io.InputStream)20