use of com.fasterxml.jackson.databind.ObjectMapper 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 com.fasterxml.jackson.databind.ObjectMapper 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 com.fasterxml.jackson.databind.ObjectMapper in project presto by prestodb.
the class QueryStatsClientModuleProvider method getModule.
@Override
public Module getModule(Configuration configuration) {
return new PrivateModule() {
@Override
protected void configure() {
bind(ObjectMapper.class).toProvider(ObjectMapperProvider.class);
}
@Inject
@Provides
@Exposed
QueryStatsClient getQueryStatsClient(ObjectMapper objectMapper, @Named("databases.presto.server_address") String serverAddress) {
// @Singleton does not work due: https://github.com/prestodb/tempto/issues/94
if (httpQueryStatsClient == null) {
HttpClientConfig httpClientConfig = new HttpClientConfig();
httpClientConfig.setKeyStorePath(configuration.getString("databases.presto.https_keystore_path").orElse(null));
httpClientConfig.setKeyStorePassword(configuration.getString("databases.presto.https_keystore_password").orElse(null));
httpQueryStatsClient = new HttpQueryStatsClient(new JettyHttpClient(httpClientConfig), objectMapper, URI.create(serverAddress));
}
return httpQueryStatsClient;
}
};
}
use of com.fasterxml.jackson.databind.ObjectMapper in project presto by prestodb.
the class TestDomain method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
TestingTypeManager typeManager = new TestingTypeManager();
TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde(typeManager);
ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
Domain domain = Domain.all(BIGINT);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
domain = Domain.none(DOUBLE);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
domain = Domain.notNull(BOOLEAN);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
domain = Domain.notNull(HYPER_LOG_LOG);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
domain = Domain.onlyNull(VARCHAR);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
domain = Domain.onlyNull(HYPER_LOG_LOG);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
domain = Domain.singleValue(BIGINT, Long.MIN_VALUE);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
domain = Domain.singleValue(ID, Long.MIN_VALUE);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
domain = Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 0L), Range.equal(BIGINT, 1L), Range.range(BIGINT, 2L, true, 3L, true)), true);
assertEquals(domain, mapper.readValue(mapper.writeValueAsString(domain), Domain.class));
}
use of com.fasterxml.jackson.databind.ObjectMapper in project presto by prestodb.
the class TestEquatableValueSet method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
TestingTypeManager typeManager = new TestingTypeManager();
TestingBlockEncodingSerde blockEncodingSerde = new TestingBlockEncodingSerde(typeManager);
ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
EquatableValueSet set = EquatableValueSet.all(ID);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
set = EquatableValueSet.none(ID);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
set = EquatableValueSet.of(ID, 1L);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
set = EquatableValueSet.of(ID, 1L, 2L);
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
set = EquatableValueSet.of(ID, 1L, 2L).complement();
assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), EquatableValueSet.class));
}
Aggregations