use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream 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.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class AbstractBindTypeProcessorTest method serializeAndParseBinary.
public int serializeAndParseBinary(Object bean, BinderType type) throws Exception {
KriptonByteArrayOutputStream bar = new KriptonByteArrayOutputStream();
KriptonBinder.bind(type).serialize(bean, bar);
String value1 = toString(bar.getByteBuffer());
System.out.println(value1);
Object bean2 = KriptonBinder.bind(type).parse(new ByteArrayInputStream(bar.getByteBuffer()), bean.getClass());
KriptonByteArrayOutputStream bar2 = new KriptonByteArrayOutputStream();
KriptonBinder.bind(type).serialize(bean2, bar2);
String value2 = toString(bar2.getByteBuffer());
System.out.println(value2);
Assert.assertTrue(value1.length() == value2.length());
return bar.getCount();
}
use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class AbstractBindTypeProcessorTest method serializeAndParseCollectionBinary.
public <E> int serializeAndParseCollectionBinary(Collection<E> list, Class<E> clazz, BinderType type) throws Exception {
KriptonByteArrayOutputStream bar = new KriptonByteArrayOutputStream();
KriptonBinder.bind(type).serializeCollection(list, clazz, bar);
String value1 = toString(bar.getByteBuffer());
Collection<E> list2 = KriptonBinder.bind(type).parseCollection(bar.getByteBufferCopy(), new ArrayList<E>(), clazz);
KriptonByteArrayOutputStream bar2 = new KriptonByteArrayOutputStream();
KriptonBinder.bind(type).serializeCollection(list2, clazz, bar2);
String value2 = toString(bar2.getByteBuffer());
System.out.println(value1);
System.out.println(value2);
Assert.assertTrue(value1.length() == value2.length());
ReflectionAssert.assertReflectionEquals(type.toString(), list, list2, ReflectionComparatorMode.LENIENT_ORDER);
//
return bar.getCount();
}
use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class AbstractBaseTest method serializeAndParseBinary.
public int serializeAndParseBinary(Object bean, BinderType type) throws Exception {
KriptonByteArrayOutputStream bar = new KriptonByteArrayOutputStream();
KriptonBinder.bind(type).serialize(bean, bar);
String value1 = toString(bar.getByteBufferCopy());
System.out.println("[[" + value1 + "]]");
Object bean2 = KriptonBinder.bind(type).parse(new ByteArrayInputStream(bar.getByteBuffer()), bean.getClass());
KriptonByteArrayOutputStream bar2 = new KriptonByteArrayOutputStream();
KriptonBinder.bind(type).serialize(bean2, bar2);
String value2 = toString(bar2.getByteBufferCopy());
if (value1.equals(value2)) {
System.out.println("[[-- same --]]");
} else {
System.out.println("[[" + value2 + "]]");
}
Assert.assertTrue(value1.length() == value2.length());
return bar.getCount();
}
use of com.abubusoft.kripton.common.KriptonByteArrayOutputStream in project kripton by xcesco.
the class AbstractBaseTest method serializeAndParseCollectionBinary.
public <E> int serializeAndParseCollectionBinary(Collection<E> list, Class<E> clazz, BinderType type) throws Exception {
KriptonByteArrayOutputStream bar = new KriptonByteArrayOutputStream();
KriptonBinder.bind(type).serializeCollection(list, clazz, bar);
String value1 = toString(bar.getByteBuffer());
System.out.println("[[" + value1 + "]]");
Collection<E> list2 = KriptonBinder.bind(type).parseCollection(bar.getByteBufferCopy(), new ArrayList<E>(), clazz);
KriptonByteArrayOutputStream bar2 = new KriptonByteArrayOutputStream();
KriptonBinder.bind(type).serializeCollection(list2, clazz, bar2);
String value2 = toString(bar2.getByteBuffer());
if (value1.equals(value2)) {
System.out.println("[[-- same --]]");
} else {
System.out.println("[[" + value2 + "]]");
}
Assert.assertTrue(value1.length() == value2.length());
ReflectionAssert.assertReflectionEquals(type.toString(), list, list2, ReflectionComparatorMode.LENIENT_ORDER);
//
return bar.getCount();
}
Aggregations