Search in sources :

Example 6 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule in project netty-socketio by mrniko.

the class JacksonJsonSupport method init.

protected void init(ObjectMapper objectMapper) {
    SimpleModule module = new SimpleModule();
    module.setSerializerModifier(modifier);
    module.addDeserializer(Event.class, eventDeserializer);
    module.addDeserializer(AckArgs.class, ackArgsDeserializer);
    objectMapper.registerModule(module);
    objectMapper.setSerializationInclusion(Include.NON_NULL);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
    objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
}
Also used : SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 7 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule 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 8 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule 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)

Example 9 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule in project presto by prestodb.

the class TestRange 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)));
    Range range = Range.all(BIGINT);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.equal(DOUBLE, 0.123);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.greaterThan(BIGINT, 0L);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.greaterThanOrEqual(VARCHAR, utf8Slice("abc"));
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.lessThan(BIGINT, Long.MAX_VALUE);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.class));
    range = Range.lessThanOrEqual(DOUBLE, Double.MAX_VALUE);
    assertEquals(range, mapper.readValue(mapper.writeValueAsString(range), Range.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 10 with SimpleModule

use of com.fasterxml.jackson.databind.module.SimpleModule in project presto by prestodb.

the class TestSortedRangeSet 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)));
    SortedRangeSet set = SortedRangeSet.all(BIGINT);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.none(DOUBLE);
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(VARCHAR, utf8Slice("abc"));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.class));
    set = SortedRangeSet.of(Range.equal(BOOLEAN, true), Range.equal(BOOLEAN, false));
    assertEquals(set, mapper.readValue(mapper.writeValueAsString(set), SortedRangeSet.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

SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)108 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)39 Test (org.junit.Test)13 Version (com.fasterxml.jackson.core.Version)8 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)8 Test (org.testng.annotations.Test)8 TestingTypeDeserializer (com.facebook.presto.spi.type.TestingTypeDeserializer)7 TestingTypeManager (com.facebook.presto.spi.type.TestingTypeManager)7 Type (com.facebook.presto.spi.type.Type)7 Block (com.facebook.presto.spi.block.Block)6 TestingBlockEncodingSerde (com.facebook.presto.spi.block.TestingBlockEncodingSerde)6 TestingBlockJsonSerde (com.facebook.presto.spi.block.TestingBlockJsonSerde)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 SimpleSerializers (com.fasterxml.jackson.databind.module.SimpleSerializers)4 IOException (java.io.IOException)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 JsonParser (com.fasterxml.jackson.core.JsonParser)3 Module (com.fasterxml.jackson.databind.Module)3 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2