use of com.abubusoft.kripton.persistence.JacksonWrapperSerializer in project kripton by xcesco.
the class Bean64BTable method serializeValueMapStringBean.
/**
* for attribute valueMapStringBean serialization
*/
public static byte[] serializeValueMapStringBean(Map<String, Bean64B> 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("element");
jacksonSerializer.writeStartArray();
for (Map.Entry<String, Bean64B> item : value.entrySet()) {
jacksonSerializer.writeStartObject();
jacksonSerializer.writeStringField("key", item.getKey());
if (item.getValue() == null) {
jacksonSerializer.writeNullField("value");
} else {
jacksonSerializer.writeFieldName("value");
bean64BBindMap.serializeOnJackson(item.getValue(), jacksonSerializer);
}
jacksonSerializer.writeEndObject();
}
jacksonSerializer.writeEndArray();
} else {
jacksonSerializer.writeNullField("element");
}
}
jacksonSerializer.writeEndObject();
jacksonSerializer.flush();
return stream.toByteArray();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.persistence.JacksonWrapperSerializer in project kripton by xcesco.
the class BindBean2SharedPreferences method serializeValueByteSet.
/**
* for attribute valueByteSet serialization
*/
protected String 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("valueByteSet");
jacksonSerializer.writeStartArray();
for (Byte 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.persistence.JacksonWrapperSerializer in project kripton by xcesco.
the class BindBean2SharedPreferences 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.persistence.JacksonWrapperSerializer in project kripton by xcesco.
the class BindBean2SharedPreferences 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()));
}
}
use of com.abubusoft.kripton.persistence.JacksonWrapperSerializer in project kripton by xcesco.
the class BindBean63SharedPreferences method serializeValueMapEnumByte.
/**
* for attribute valueMapEnumByte serialization
*/
protected String serializeValueMapEnumByte(HashMap<EnumType, 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
if (value.size() > 0) {
jacksonSerializer.writeFieldName("valueMapEnumByte");
jacksonSerializer.writeStartArray();
for (Map.Entry<EnumType, Byte> item : value.entrySet()) {
jacksonSerializer.writeStartObject();
jacksonSerializer.writeStringField("key", item.getKey().toString());
if (item.getValue() == null) {
jacksonSerializer.writeNullField("value");
} else {
jacksonSerializer.writeNumberField("value", item.getValue());
}
jacksonSerializer.writeEndObject();
}
jacksonSerializer.writeEndArray();
} else {
jacksonSerializer.writeNullField("valueMapEnumByte");
}
}
jacksonSerializer.writeEndObject();
jacksonSerializer.flush();
return stream.toString();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
Aggregations