use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class BiMapperTest method serialize.
@Test
public void serialize() throws Exception {
// Check proper serialization of the structure/single object
ZonedDateTime now = ZonedDateTime.now();
Binder res = DefaultBiMapper.serialize(Binder.of("time", now, "hello", "world"));
assertEquals("world", res.get("hello"));
assertEquals("unixtime", res.getStringOrThrow("time", "__type"));
Binder restored = DefaultBiMapper.deserialize(res);
assertEquals(now.truncatedTo(ChronoUnit.SECONDS), restored.get("time"));
assertEquals(now.truncatedTo(ChronoUnit.SECONDS), DefaultBiMapper.deserialize(DefaultBiMapper.serialize(now)));
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class BiMapperTest method autoSerializable.
@Test
public void autoSerializable() throws Exception {
Test1 t1 = new Test1("foo");
DefaultBiMapper.registerClass(Test1.class);
Binder s = DefaultBiMapper.serialize(t1);
assertEquals(s.getStringOrThrow("__type"), "foobar1");
assertEquals(s.getStringOrThrow("value"), "foo");
Test1 t2 = DefaultBiMapper.deserialize(s);
assertThat(t2, instanceOf(Test1.class));
assertEquals("foo", t2.getValue());
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class BiMapperTest method autoSerializableInheritance.
@Test
public void autoSerializableInheritance() throws Exception {
Test1 t1 = new Test2("foo");
DefaultBiMapper.registerClass(Test2.class);
Binder s = DefaultBiMapper.serialize(t1);
assertEquals(s.getStringOrThrow("__type"), "net.sergeych.biserializer.Test2");
Test2 t2 = DefaultBiMapper.deserialize(s);
assertThat(t2, instanceOf(Test1.class));
assertEquals("bad", t2.getValue());
assertEquals("foo", t2.getBar());
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class TestBoss method emptyStrings.
@Test
public void emptyStrings() throws Exception {
Object xo = JsonTool.fromJson("{\"text\":\"\",\"type\":\"p2pchat\",\"from_party_id\":\"1271\"}");
Binder b = Binder.from(xo);
Bytes bb = Boss.dump(b);
String x = (String) Boss.unpack(bb.toArray()).getStringOrThrow("text");
assertEquals("", x);
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class DeltaTest method nestedMaps.
@Test
public void nestedMaps() throws Exception {
Binder a = Binder.fromKeysValues("hello", "world", "foo", "bar");
Binder b = Binder.fromKeysValues("hello", "world", "foo", "bar");
Binder r1 = Binder.fromKeysValues("nice", "day", "root", a);
Binder r2 = Binder.fromKeysValues("nice", "day", "root", b);
assertNull(Delta.between(r1, r2));
b.put("foo", 117);
MapDelta rd = Delta.between(r1, r2);
assertNotNull(rd);
assertFalse(rd.isEmpty());
assertEquals(1, rd.getChanges().size());
MapDelta md = (MapDelta) rd.getChange("root");
assertNotNull(md);
assertEquals(1, md.getChanges().size());
ChangedItem ci = (ChangedItem) md.getChange("foo");
assertEquals("bar", ci.oldValue());
assertEquals(117, ci.newValue());
assertEquals(1, rd.getNestedDelta().size());
}
Aggregations