use of com.abubusoft.kripton.persistence.JacksonWrapperSerializer in project kripton by xcesco.
the class BindBean63SharedPreferences method serializeValueMapStringByte.
/**
* for attribute valueMapStringByte serialization
*/
protected String serializeValueMapStringByte(Map<String, 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("valueMapStringByte");
jacksonSerializer.writeStartArray();
for (Map.Entry<String, Byte> item : value.entrySet()) {
jacksonSerializer.writeStartObject();
jacksonSerializer.writeStringField("key", item.getKey());
if (item.getValue() == null) {
jacksonSerializer.writeNullField("value");
} else {
jacksonSerializer.writeNumberField("value", item.getValue());
}
jacksonSerializer.writeEndObject();
}
jacksonSerializer.writeEndArray();
} else {
jacksonSerializer.writeNullField("valueMapStringByte");
}
}
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 CountryTable method serializeTranslatedName.
/**
* for attribute translatedName serialization
*/
public static byte[] serializeTranslatedName(Map<Translation, 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++;
// write wrapper tag
if (value.size() > 0) {
jacksonSerializer.writeFieldName("element");
jacksonSerializer.writeStartArray();
for (Map.Entry<Translation, String> item : value.entrySet()) {
jacksonSerializer.writeStartObject();
jacksonSerializer.writeStringField("key", item.getKey().toString());
if (item.getValue() == null) {
jacksonSerializer.writeNullField("value");
} else {
jacksonSerializer.writeStringField("value", item.getValue());
}
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 ByteBeanTable method serializeValue2.
/**
* for attribute value2 serialization
*/
public static byte[] serializeValue2(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++;
int n = value.length;
Byte item;
// write wrapper tag
jacksonSerializer.writeFieldName("element");
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.toByteArray();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.persistence.JacksonWrapperSerializer in project kripton by xcesco.
the class ByteDaoImpl method serializer1.
/**
* for param serializer1 serialization
*/
private byte[] serializer1(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;
int fieldCount = 0;
jacksonSerializer.writeStartObject();
if (value != null) {
int n = value.length;
Byte item;
// write wrapper tag
jacksonSerializer.writeFieldName("element");
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.toByteArray();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
use of com.abubusoft.kripton.persistence.JacksonWrapperSerializer in project kripton by xcesco.
the class CharBeanTable method serializeValue.
/**
* for attribute value serialization
*/
public static byte[] serializeValue(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("element");
jacksonSerializer.writeStartArray();
for (int i = 0; i < n; i++) {
item = value[i];
jacksonSerializer.writeNumber(item);
}
jacksonSerializer.writeEndArray();
}
jacksonSerializer.writeEndObject();
jacksonSerializer.flush();
return stream.toByteArray();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
Aggregations