use of com.abubusoft.kripton.exception.KriptonRuntimeException 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()));
}
}
use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class BindBeanSharedPreferences method serializeValueLinkedMapStringBean.
/**
* for attribute valueLinkedMapStringBean serialization
*/
protected String 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("valueLinkedMapStringBean");
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("valueLinkedMapStringBean");
}
}
jacksonSerializer.writeEndObject();
jacksonSerializer.flush();
return stream.toString();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class BindBeanSharedPreferences method serializeValueLongList.
/**
* for attribute valueLongList serialization
*/
protected String 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("valueLongList");
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.toString();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class BindBeanSharedPreferences method serializeValueBean.
/**
* for attribute valueBean serialization
*/
protected String serializeValueBean(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;
int fieldCount = 0;
if (value != null) {
fieldCount++;
beanBindMap.serializeOnJackson(value, jacksonSerializer);
}
jacksonSerializer.flush();
return stream.toString();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.exception.KriptonRuntimeException in project kripton by xcesco.
the class BindBeanSharedPreferences method parseValueCharTypeArray.
/**
* for attribute valueCharTypeArray parsing
*/
protected char[] parseValueCharTypeArray(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();
char[] result = null;
if (jacksonParser.currentToken() == JsonToken.START_ARRAY) {
ArrayList<Character> collection = new ArrayList<>();
Character item = null;
while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
if (jacksonParser.currentToken() == JsonToken.VALUE_NULL) {
item = null;
} else {
item = Character.valueOf((char) jacksonParser.getIntValue());
}
collection.add(item);
}
result = CollectionUtils.asCharacterTypeArray(collection);
}
return result;
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
Aggregations