use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class Bean2Table method parseValueBeanSet.
/**
* for attribute valueBeanSet parsing
*/
public static LinkedHashSet<Bean> parseValueBeanSet(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<Bean> result = null;
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
LinkedHashSet<Bean> collection = new LinkedHashSet<>();
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 = collection;
}
return result;
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class Bean2Table 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()));
}
}
use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class Bean2Table method serializeValueByteSet.
/**
* for attribute valueByteSet serialization
*/
public static byte[] serializeValueByteSet(Set<Byte> 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 (Byte item : value) {
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()));
}
}
use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class BindBean2SharedPreferences method serializeValueCharTypeArray.
/**
* for attribute valueCharTypeArray serialization
*/
protected String 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("valueCharTypeArray");
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = value[i];
jacksonSerializer.writeNumber(item);
}
jacksonSerializer.writeEndArray();
}
jacksonSerializer.writeEndObject();
jacksonSerializer.flush();
return stream.toString();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class BindBean2SharedPreferences method serializeValueLongTypeArray.
/**
* for attribute valueLongTypeArray serialization
*/
protected String serializeValueLongTypeArray(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.length;
long item;
// write wrapper tag
jacksonSerializer.writeFieldName("valueLongTypeArray");
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = value[i];
jacksonSerializer.writeNumber(item);
}
jacksonSerializer.writeEndArray();
}
jacksonSerializer.writeEndObject();
jacksonSerializer.flush();
return stream.toString();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
Aggregations