Search in sources :

Example 1 with BeanInner

use of sqlite.kripton58.BeanInner in project kripton by xcesco.

the class BeanDaoImpl method serializer1.

/**
 * for param serializer1 serialization
 */
private byte[] serializer1(BeanInner[] 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;
            BeanInner 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 {
                    beanInnerBindMap.serializeOnJackson(item, jacksonSerializer);
                }
            }
            jacksonSerializer.writeEndArray();
        }
        jacksonSerializer.writeEndObject();
        jacksonSerializer.flush();
        return stream.toByteArray();
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : BeanInner(sqlite.kripton58.BeanInner) 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 2 with BeanInner

use of sqlite.kripton58.BeanInner in project kripton by xcesco.

the class BeanDaoImpl method parser1.

/**
 * for param parser1 parsing
 */
private BeanInner[] 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();
        BeanInner[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<BeanInner> collection = new ArrayList<>();
            BeanInner item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = beanInnerBindMap.parseOnJackson(jacksonParser);
                }
                collection.add(item);
            }
            result = CollectionUtils.asArray(collection, new BeanInner[collection.size()]);
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : BeanInner(sqlite.kripton58.BeanInner) 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 3 with BeanInner

use of sqlite.kripton58.BeanInner in project kripton by xcesco.

the class BeanBeanBindMap method parseOnJackson.

/**
 * parse with jackson
 */
@Override
public BeanBean parseOnJackson(JsonParser jacksonParser) throws Exception {
    BeanBean instance = new BeanBean();
    String fieldName;
    if (jacksonParser.currentToken() == null) {
        jacksonParser.nextToken();
    }
    if (jacksonParser.currentToken() != 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.setId(jacksonParser.getLongValue());
                break;
            case "value":
                // field value (mapped with "value")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<BeanInner> collection = new ArrayList<>();
                    BeanInner item = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                            item = null;
                        } else {
                            item = beanInnerBindMap.parseOnJackson(jacksonParser);
                        }
                        collection.add(item);
                    }
                    instance.setValue(CollectionUtils.asArray(collection, new BeanInner[collection.size()]));
                }
                break;
            case "value2":
                // field value2 (mapped with "value2")
                if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
                    ArrayList<BeanInner> collection = new ArrayList<>();
                    BeanInner item = null;
                    while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                        if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                            item = null;
                        } else {
                            item = beanInnerBindMap.parseOnJackson(jacksonParser);
                        }
                        collection.add(item);
                    }
                    instance.setValue2(CollectionUtils.asArray(collection, new BeanInner[collection.size()]));
                }
                break;
            default:
                jacksonParser.skipChildren();
                break;
        }
    }
    return instance;
}
Also used : BeanInner(sqlite.kripton58.BeanInner) ArrayList(java.util.ArrayList)

Example 4 with BeanInner

use of sqlite.kripton58.BeanInner in project kripton by xcesco.

the class BeanBeanTable method parseValue.

/**
 * for attribute value parsing
 */
public static BeanInner[] 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();
        BeanInner[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<BeanInner> collection = new ArrayList<>();
            BeanInner item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = beanInnerBindMap.parseOnJackson(jacksonParser);
                }
                collection.add(item);
            }
            result = CollectionUtils.asArray(collection, new BeanInner[collection.size()]);
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : BeanInner(sqlite.kripton58.BeanInner) 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 5 with BeanInner

use of sqlite.kripton58.BeanInner in project kripton by xcesco.

the class BeanBeanTable method parseValue2.

/**
 * for attribute value2 parsing
 */
public static BeanInner[] 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();
        BeanInner[] result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            ArrayList<BeanInner> collection = new ArrayList<>();
            BeanInner item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = beanInnerBindMap.parseOnJackson(jacksonParser);
                }
                collection.add(item);
            }
            result = CollectionUtils.asArray(collection, new BeanInner[collection.size()]);
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : BeanInner(sqlite.kripton58.BeanInner) 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)

Aggregations

BeanInner (sqlite.kripton58.BeanInner)33 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)18 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)18 ArrayList (java.util.ArrayList)14 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)9 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)9 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)9 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)9 JsonParser (com.fasterxml.jackson.core.JsonParser)9 LinkedList (java.util.LinkedList)3