use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class BindBean2SharedPreferences method serializeValueStringArray.
/**
* for attribute valueStringArray serialization
*/
protected String serializeValueStringArray(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.length;
String item;
// write wrapper tag
jacksonSerializer.writeFieldName("valueStringArray");
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = value[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.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class BindBean2SharedPreferences method serializeValueLongArray.
/**
* for attribute valueLongArray serialization
*/
protected String serializeValueLongArray(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("valueLongArray");
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.toString();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class BindBean2SharedPreferences 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.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class BindBeanSharedPreferences method serializeValueFloatSet.
/**
* for attribute valueFloatSet serialization
*/
protected String serializeValueFloatSet(HashSet<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;
jacksonSerializer.writeStartObject();
int fieldCount = 0;
if (value != null) {
fieldCount++;
// write wrapper tag
jacksonSerializer.writeFieldName("valueFloatSet");
jacksonSerializer.writeStartArray();
for (Float item : value) {
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.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class BindBeanSharedPreferences method serializeValueShortSet.
/**
* for attribute valueShortSet serialization
*/
protected String serializeValueShortSet(HashSet<Short> 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("valueShortSet");
jacksonSerializer.writeStartArray();
for (Short item : value) {
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()));
}
}
Aggregations