Search in sources :

Example 1 with JacksonWrapperSerializer

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

the class DaoBean05Impl method serializer1.

/**
 * for param serializer1 serialization
 */
private byte[] serializer1(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;
        int fieldCount = 0;
        jacksonSerializer.writeStartObject();
        if (value != null) {
            jacksonSerializer.writeNumberField("element", value);
        }
        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 2 with JacksonWrapperSerializer

use of com.abubusoft.kripton.persistence.JacksonWrapperSerializer 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 3 with JacksonWrapperSerializer

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

the class DoubleBeanTable method serializeValue.

/**
 * for attribute value serialization
 */
public static byte[] serializeValue(double[] 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;
            double 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 4 with JacksonWrapperSerializer

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

the class DoubleDaoImpl method serializer2.

/**
 * for param serializer2 serialization
 */
private byte[] serializer2(Double[] 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;
            Double 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 {
                    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 5 with JacksonWrapperSerializer

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

the class FloatDaoImpl method serializer2.

/**
 * for param serializer2 serialization
 */
private byte[] serializer2(Float[] 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;
            Float 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 {
                    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

KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)258 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)258 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)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 XmlWrapperSerializer (com.abubusoft.kripton.persistence.XmlWrapperSerializer)1 XMLSerializer (com.abubusoft.kripton.xml.XMLSerializer)1 IOException (java.io.IOException)1