Search in sources :

Example 86 with KriptonRuntimeException

use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.

the class BeanDaoImpl method parser1.

/**
 * for param parser1 parsing
 */
private HashSet<BigDecimal> 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();
        HashSet<BigDecimal> result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            HashSet<BigDecimal> collection = new HashSet<>();
            BigDecimal item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = BigDecimalUtils.read(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) BigDecimal(java.math.BigDecimal) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException) JsonParser(com.fasterxml.jackson.core.JsonParser) HashSet(java.util.HashSet)

Example 87 with KriptonRuntimeException

use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.

the class BeanDaoImpl method serializer1.

/**
 * for param serializer1 serialization
 */
private byte[] serializer1(HashSet<BigDecimal> 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) {
            // write wrapper tag
            jacksonSerializer.writeFieldName("element");
            jacksonSerializer.writeStartArray();
            for (BigDecimal item : value) {
                if (item == null) {
                    jacksonSerializer.writeNull();
                } else {
                    jacksonSerializer.writeString(BigDecimalUtils.write(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) BigDecimal(java.math.BigDecimal) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException)

Example 88 with KriptonRuntimeException

use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.

the class BeanTable method serializeValueBigDecimalSet.

/**
 * for attribute valueBigDecimalSet serialization
 */
public static byte[] serializeValueBigDecimalSet(HashSet<BigDecimal> 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 (BigDecimal item : value) {
                if (item == null) {
                    jacksonSerializer.writeNull();
                } else {
                    jacksonSerializer.writeString(BigDecimalUtils.write(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) BigDecimal(java.math.BigDecimal) KriptonRuntimeException(com.abubusoft.kripton.exception.KriptonRuntimeException)

Example 89 with KriptonRuntimeException

use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.

the class BeanTable method parseValueIntegerSet.

/**
 * for attribute valueIntegerSet parsing
 */
public static LinkedHashSet<Integer> parseValueIntegerSet(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();
        LinkedHashSet<Integer> result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            LinkedHashSet<Integer> collection = new LinkedHashSet<>();
            Integer item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = jacksonParser.getIntValue();
                }
                collection.add(item);
            }
            result = collection;
        }
        return result;
    } catch (Exception e) {
        throw (new KriptonRuntimeException(e.getMessage()));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) 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 90 with KriptonRuntimeException

use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.

the class BeanTable method parseValueFloatSet.

/**
 * for attribute valueFloatSet parsing
 */
public static HashSet<Float> parseValueFloatSet(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();
        HashSet<Float> result = null;
        if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
            HashSet<Float> collection = new HashSet<>();
            Float item = null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
                if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
                    item = null;
                } else {
                    item = jacksonParser.getFloatValue();
                }
                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) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)721 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)514 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)258 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)258 JsonParser (com.fasterxml.jackson.core.JsonParser)258 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)257 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)257 ArrayList (java.util.ArrayList)143 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)120 KriptonContentValues (com.abubusoft.kripton.android.sqlite.KriptonContentValues)68 HashMap (java.util.HashMap)43 HashSet (java.util.HashSet)40 LinkedHashSet (java.util.LinkedHashSet)38 Cursor (android.database.Cursor)31 LinkedList (java.util.LinkedList)26 Map (java.util.Map)24 LinkedHashMap (java.util.LinkedHashMap)18 BeanInner (sqlite.kripton58.BeanInner)18 BigDecimal (java.math.BigDecimal)12 Time (java.sql.Time)10