use of io.requery.jackson.EntityMapper in project requery by requery.
the class JacksonTest method testOneToManySerialize.
@Test
public void testOneToManySerialize() {
Event event = new Event();
UUID id = UUID.randomUUID();
event.setId(id);
event.setName("test");
Tag t1 = new Tag();
t1.setId(UUID.randomUUID());
Tag t2 = new Tag();
t2.setId(UUID.randomUUID());
event.getTags().add(t1);
event.getTags().add(t2);
Place p = new Place();
p.setId("SF");
p.setName("San Francisco, CA");
event.setPlace(p);
data.insert(event);
ObjectMapper mapper = new EntityMapper(Models.MODEL3, data);
StringWriter writer = new StringWriter();
try {
mapper.writeValue(writer, event);
} catch (IOException e) {
throw new RuntimeException(e);
}
String value = writer.toString();
System.out.println(value);
try {
Event read = mapper.readValue(value, Event.class);
assertSame(event, read);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.requery.jackson.EntityMapper in project requery by requery.
the class JacksonTest method testManyToManySerialize.
@Test
public void testManyToManySerialize() {
Tag t1 = new Tag();
t1.setId(UUID.randomUUID());
for (int i = 0; i < 3; i++) {
Event event = new Event();
UUID id = UUID.randomUUID();
event.setId(id);
event.setName("event" + i);
t1.getEvents().add(event);
}
data.insert(t1);
ObjectMapper mapper = new EntityMapper(Models.MODEL3, data);
StringWriter writer = new StringWriter();
try {
mapper.writeValue(writer, t1);
} catch (IOException e) {
throw new RuntimeException(e);
}
String value = writer.toString();
System.out.println(value);
try {
Tag tag = mapper.readValue(value, Tag.class);
assertSame(t1, tag);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.requery.jackson.EntityMapper in project requery by requery.
the class JacksonTest method testEmbedSerialize.
@Test
public void testEmbedSerialize() {
LocationEntity t1 = new LocationEntity();
t1.setId(1);
data.insert(t1);
ObjectMapper mapper = new EntityMapper(Models.MODEL3, data);
StringWriter writer = new StringWriter();
try {
mapper.writeValue(writer, t1);
} catch (IOException e) {
throw new RuntimeException(e);
}
String value = writer.toString();
System.out.println(value);
try {
LocationEntity location = mapper.readValue(value, LocationEntity.class);
assertSame(t1, location);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations