use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class BindBeanSharedPreferences 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()));
}
}
use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class BindBeanSharedPreferences method serializeValueStrinList.
/**
* for attribute valueStrinList serialization
*/
protected String serializeValueStrinList(LinkedList<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++;
int n = value.size();
String item;
// write wrapper tag
jacksonSerializer.writeFieldName("valueStrinList");
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = value.get(i);
if (item == null) {
jacksonSerializer.writeNull();
} else {
jacksonSerializer.writeString(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 BindBeanSharedPreferences method parseValueBean.
/**
* for attribute valueBean parsing
*/
protected Bean parseValueBean(String input) {
if (input == null) {
return null;
}
KriptonJsonContext context = KriptonBinder.jsonBind();
try (JacksonWrapperParser wrapper = context.createParser(input)) {
JsonParser jacksonParser = wrapper.jacksonParser;
// START_OBJECT
jacksonParser.nextToken();
Bean result = null;
if (jacksonParser.currentToken() == JsonToken.START_OBJECT) {
result = beanBindMap.parseOnJackson(jacksonParser);
}
return result;
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class BindBeanSharedPreferences method parseValueLongArray.
/**
* for attribute valueLongArray parsing
*/
protected Long[] parseValueLongArray(String 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();
Long[] result = null;
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
ArrayList<Long> collection = new ArrayList<>();
Long item = null;
while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
item = null;
} else {
item = jacksonParser.getLongValue();
}
collection.add(item);
}
result = CollectionUtils.asLongArray(collection);
}
return result;
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.KriptonJsonContext in project kripton by xcesco.
the class BindBeanSharedPreferences method parseValueLinkedMapStringBean.
/**
* for attribute valueLinkedMapStringBean parsing
*/
protected LinkedHashMap<String, Bean> parseValueLinkedMapStringBean(String 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();
LinkedHashMap<String, Bean> result = null;
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
LinkedHashMap<String, Bean> collection = new LinkedHashMap<>();
String key = null;
Bean value = null;
while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
jacksonParser.nextValue();
key = jacksonParser.getText();
jacksonParser.nextValue();
if (jacksonParser.currentToken() == JsonToken.START_OBJECT) {
value = beanBindMap.parseOnJackson(jacksonParser);
}
collection.put(key, value);
key = null;
value = null;
jacksonParser.nextToken();
}
result = collection;
}
return result;
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
Aggregations