Search in sources :

Example 51 with KriptonJsonContext

use of com.abubusoft.kripton.KriptonJsonContext 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 52 with KriptonJsonContext

use of com.abubusoft.kripton.KriptonJsonContext 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)

Example 53 with KriptonJsonContext

use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.

the class BeanDaoImpl method serializer1.

/**
 * for param serializer1 serialization
 */
private byte[] serializer1(Bean[] value) {
    if (value == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (KriptonByteArrayOutputStream stream = new KriptonByteArrayOutputStream();
        JacksonWrapperSerializer wrapper = context.createSerializer(stream)) {
        JsonGenerator jacksonSerializer = wrapper.jacksonGenerator;
        int fieldCount = 0;
        jacksonSerializer.writeStartObject();
        if (value != null) {
            int n = value.length;
            Bean item;
            // write wrapper tag
            jacksonSerializer.writeFieldName("element");
            jacksonSerializer.writeStartArray();
            for (int i = 0; i < n; i++) {
                item = value[i];
                if (item == null) {
                    jacksonSerializer.writeNull();
                } else {
                    beanBindMap.serializeOnJackson(item, jacksonSerializer);
                }
            }
            jacksonSerializer.writeEndArray();
        }
        jacksonSerializer.writeEndObject();
        jacksonSerializer.flush();
        return stream.toByteArray();
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) KriptonByteArrayOutputStream(com.abubusoft.kripton.common.KriptonByteArrayOutputStream) KriptonJsonContext(com.abubusoft.kripton.KriptonJsonContext) JacksonWrapperSerializer(com.abubusoft.kripton.persistence.JacksonWrapperSerializer) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException)

Example 54 with KriptonJsonContext

use of com.abubusoft.kripton.KriptonJsonContext 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 55 with KriptonJsonContext

use of com.abubusoft.kripton.KriptonJsonContext 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)

Aggregations

KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)518 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)514 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)257 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)257 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)257 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)257 JsonParser (com.fasterxml.jackson.core.JsonParser)257 ArrayList (java.util.ArrayList)142 HashMap (java.util.HashMap)42 HashSet (java.util.HashSet)40 LinkedHashSet (java.util.LinkedHashSet)38 LinkedList (java.util.LinkedList)26 Map (java.util.Map)23 BeanInner (sqlite.kripton58.BeanInner)18 LinkedHashMap (java.util.LinkedHashMap)16 BigDecimal (java.math.BigDecimal)12 Time (java.sql.Time)10 Date (java.util.Date)2 Test (org.junit.Test)2 AbstractBaseTest (bind.AbstractBaseTest)1