Search in sources :

Example 26 with KriptonByteArrayOutputStream

use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.

the class BeanTable method serializeValueCharTypeArray.

/**
 * for attribute valueCharTypeArray serialization
 */
public static byte[] serializeValueCharTypeArray(char[] value) {
    if (value == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (KriptonByteArrayOutputStream stream = new KriptonByteArrayOutputStream();
        JacksonWrapperSerializer wrapper = context.createSerializer(stream)) {
        JsonGenerator jacksonSerializer = wrapper.jacksonGenerator;
        jacksonSerializer.writeStartObject();
        int fieldCount = 0;
        if (value != null) {
            fieldCount++;
            int n = value.length;
            char item;
            // write wrapper tag
            jacksonSerializer.writeFieldName("element");
            jacksonSerializer.writeStartArray();
            for (int i = 0; i < n; i++) {
                item = value[i];
                jacksonSerializer.writeNumber(item);
            }
            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 27 with KriptonByteArrayOutputStream

use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.

the class BeanTable method serializeValueMapStringBean.

/**
 * for attribute valueMapStringBean serialization
 */
public static byte[] serializeValueMapStringBean(Map<String, 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;
        jacksonSerializer.writeStartObject();
        int fieldCount = 0;
        if (value != null) {
            fieldCount++;
            // write wrapper tag
            if (value.size() > 0) {
                jacksonSerializer.writeFieldName("element");
                jacksonSerializer.writeStartArray();
                for (Map.Entry<String, Bean> item : value.entrySet()) {
                    jacksonSerializer.writeStartObject();
                    jacksonSerializer.writeStringField("key", item.getKey());
                    if (item.getValue() == null) {
                        jacksonSerializer.writeNullField("value");
                    } else {
                        jacksonSerializer.writeFieldName("value");
                        beanBindMap.serializeOnJackson(item.getValue(), jacksonSerializer);
                    }
                    jacksonSerializer.writeEndObject();
                }
                jacksonSerializer.writeEndArray();
            } else {
                jacksonSerializer.writeNullField("element");
            }
        }
        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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException)

Example 28 with KriptonByteArrayOutputStream

use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.

the class BeanTable method serializeValueLinkedMapStringBean.

/**
 * for attribute valueLinkedMapStringBean serialization
 */
public static byte[] serializeValueLinkedMapStringBean(LinkedHashMap<String, 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;
        jacksonSerializer.writeStartObject();
        int fieldCount = 0;
        if (value != null) {
            fieldCount++;
            // write wrapper tag
            if (value.size() > 0) {
                jacksonSerializer.writeFieldName("element");
                jacksonSerializer.writeStartArray();
                for (Map.Entry<String, Bean> item : value.entrySet()) {
                    jacksonSerializer.writeStartObject();
                    jacksonSerializer.writeStringField("key", item.getKey());
                    if (item.getValue() == null) {
                        jacksonSerializer.writeNullField("value");
                    } else {
                        jacksonSerializer.writeFieldName("value");
                        beanBindMap.serializeOnJackson(item.getValue(), jacksonSerializer);
                    }
                    jacksonSerializer.writeEndObject();
                }
                jacksonSerializer.writeEndArray();
            } else {
                jacksonSerializer.writeNullField("element");
            }
        }
        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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException)

Example 29 with KriptonByteArrayOutputStream

use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.

the class BeanTable method serializeValueSetString.

/**
 * for attribute valueSetString serialization
 */
public static byte[] serializeValueSetString(Set<String> value) {
    if (value == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (KriptonByteArrayOutputStream stream = new KriptonByteArrayOutputStream();
        JacksonWrapperSerializer wrapper = context.createSerializer(stream)) {
        JsonGenerator jacksonSerializer = wrapper.jacksonGenerator;
        jacksonSerializer.writeStartObject();
        int fieldCount = 0;
        if (value != null) {
            fieldCount++;
            // write wrapper tag
            jacksonSerializer.writeFieldName("element");
            jacksonSerializer.writeStartArray();
            for (String item : value) {
                if (item == null) {
                    jacksonSerializer.writeNull();
                } else {
                    jacksonSerializer.writeString(item);
                }
            }
            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 30 with KriptonByteArrayOutputStream

use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.

the class BeanTable method serializeValueLongList.

/**
 * for attribute valueLongList serialization
 */
public static byte[] serializeValueLongList(LinkedList<Long> value) {
    if (value == null) {
        return null;
    }
    KriptonJsonContext context = KriptonBinder.jsonBind();
    try (KriptonByteArrayOutputStream stream = new KriptonByteArrayOutputStream();
        JacksonWrapperSerializer wrapper = context.createSerializer(stream)) {
        JsonGenerator jacksonSerializer = wrapper.jacksonGenerator;
        jacksonSerializer.writeStartObject();
        int fieldCount = 0;
        if (value != null) {
            fieldCount++;
            int n = value.size();
            Long item;
            // write wrapper tag
            jacksonSerializer.writeFieldName("element");
            jacksonSerializer.writeStartArray();
            for (int i = 0; i < n; i++) {
                item = value.get(i);
                if (item == null) {
                    jacksonSerializer.writeNull();
                } else {
                    jacksonSerializer.writeNumber(item);
                }
            }
            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)

Aggregations

KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)264 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)257 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)257 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)257 HashMap (java.util.HashMap)23 Map (java.util.Map)23 BeanInner (sqlite.kripton58.BeanInner)9 LinkedHashMap (java.util.LinkedHashMap)8 BigDecimal (java.math.BigDecimal)6 Time (java.sql.Time)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 BinderContext (com.abubusoft.kripton.BinderContext)1 KriptonCborContext (com.abubusoft.kripton.KriptonCborContext)1 KriptonPropertiesContext (com.abubusoft.kripton.KriptonPropertiesContext)1 KriptonXmlContext (com.abubusoft.kripton.KriptonXmlContext)1 KriptonYamlContext (com.abubusoft.kripton.KriptonYamlContext)1