Search in sources :

Example 31 with JacksonWrapperParser

use of com.abubusoft.kripton.persistence.JacksonWrapperParser in project kripton by xcesco.

the class BeanDaoImpl method parser1.

/**
 * for param parser1 parsing
 */
private Bean[] 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();
        Bean[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<Bean> collection = new ArrayList<>();
            Bean item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = beanBindMap.parseOnJackson(jacksonParser);
                }
                collection.add(item);
            }
            result = CollectionUtils.asArray(collection, new Bean[collection.size()]);
        }
        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 32 with JacksonWrapperParser

use of com.abubusoft.kripton.persistence.JacksonWrapperParser in project kripton by xcesco.

the class BeanTable method parseValueStrinList.

/**
 * for attribute valueStrinList parsing
 */
public static LinkedList<String> parseValueStrinList(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();
        LinkedList<String> result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            LinkedList<String> collection = new LinkedList<>();
            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) LinkedList(java.util.LinkedList) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 33 with JacksonWrapperParser

use of com.abubusoft.kripton.persistence.JacksonWrapperParser in project kripton by xcesco.

the class BeanTable method parseValueLongTypeArray.

/**
 * for attribute valueLongTypeArray parsing
 */
public static long[] parseValueLongTypeArray(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();
        long[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<Long> collection = new ArrayList<>();
            Long item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = jacksonParser.getLongValue();
                }
                collection.add(item);
            }
            result = CollectionUtils.asLongTypeArray(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 34 with JacksonWrapperParser

use of com.abubusoft.kripton.persistence.JacksonWrapperParser in project kripton by xcesco.

the class BeanTable method parseValueStringArray.

/**
 * for attribute valueStringArray parsing
 */
public static String[] parseValueStringArray(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();
        String[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<String> collection = new ArrayList<>();
            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 = CollectionUtils.asArray(collection, new String[collection.size()]);
        }
        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 35 with JacksonWrapperParser

use of com.abubusoft.kripton.persistence.JacksonWrapperParser in project kripton by xcesco.

the class BindBeanSharedPreferences method parseValueBean.

/**
 * for attribute valueBean parsing
 */
protected Bean parseValueBean(String input) {
    if (input == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (JacksonWrapperParser wrapper = context.createParser(input)) {
        JsonParser jacksonParser = wrapper.jacksonParser;
        // START_OBJECT
        jacksonParser.nextToken();
        Bean result = null;
        if (jacksonParser.currentToken() == JsonToken.START_OBJECT) {
            result = beanBindMap.parseOnJackson(jacksonParser);
        }
        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)

Aggregations

KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)258 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)258 JsonParser (com.fasterxml.jackson.core.JsonParser)258 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 ArrayList (java.util.ArrayList)141 HashSet (java.util.HashSet)40 LinkedHashSet (java.util.LinkedHashSet)38 LinkedList (java.util.LinkedList)26 HashMap (java.util.HashMap)19 BeanInner (sqlite.kripton58.BeanInner)9 LinkedHashMap (java.util.LinkedHashMap)8 BigDecimal (java.math.BigDecimal)6 Time (java.sql.Time)5 Date (java.util.Date)1