Search in sources :

Example 91 with ObjectMapper

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);
    }
}
Also used : StringWriter(java.io.StringWriter) Event(io.requery.test.model3.Event) Tag(io.requery.test.model3.Tag) IOException(java.io.IOException) UUID(java.util.UUID) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EntityMapper(io.requery.jackson.EntityMapper) Test(org.junit.Test)

Example 92 with ObjectMapper

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);
    }
}
Also used : StringWriter(java.io.StringWriter) Event(io.requery.test.model3.Event) Tag(io.requery.test.model3.Tag) IOException(java.io.IOException) UUID(java.util.UUID) Place(io.requery.test.model3.Place) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EntityMapper(io.requery.jackson.EntityMapper) Test(org.junit.Test)

Example 93 with ObjectMapper

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;
        }
    };
}
Also used : Named(javax.inject.Named) HttpClientConfig(io.airlift.http.client.HttpClientConfig) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) PrivateModule(com.google.inject.PrivateModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 94 with ObjectMapper

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));
}
Also used : Type(com.facebook.presto.spi.type.Type) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) TestingBlockEncodingSerde(com.facebook.presto.spi.block.TestingBlockEncodingSerde) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) Block(com.facebook.presto.spi.block.Block) TestingBlockJsonSerde(com.facebook.presto.spi.block.TestingBlockJsonSerde) TestingTypeManager(com.facebook.presto.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Example 95 with ObjectMapper

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));
}
Also used : Type(com.facebook.presto.spi.type.Type) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) TestingBlockEncodingSerde(com.facebook.presto.spi.block.TestingBlockEncodingSerde) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) Block(com.facebook.presto.spi.block.Block) TestingBlockJsonSerde(com.facebook.presto.spi.block.TestingBlockJsonSerde) TestingTypeManager(com.facebook.presto.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) Test(org.testng.annotations.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1706 Test (org.junit.Test)641 JsonNode (com.fasterxml.jackson.databind.JsonNode)270 IOException (java.io.IOException)238 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)183 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Map (java.util.Map)124 HashMap (java.util.HashMap)119 ArrayList (java.util.ArrayList)81 File (java.io.File)72 InputStream (java.io.InputStream)65 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)55 JCodeModel (com.sun.codemodel.JCodeModel)52 List (java.util.List)49 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)47 JPackage (com.sun.codemodel.JPackage)44 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)41 JsonException (jmri.server.json.JsonException)41 JType (com.sun.codemodel.JType)38 Test (org.testng.annotations.Test)37