Search in sources :

Example 11 with ObjectMapperProvider

use of io.airlift.json.ObjectMapperProvider in project presto by prestodb.

the class TestMarker 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)));
    Marker marker = Marker.above(BIGINT, 0L);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.exactly(VARCHAR, utf8Slice("abc"));
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.below(DOUBLE, 0.123);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.exactly(BOOLEAN, true);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.upperUnbounded(BIGINT);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.class));
    marker = Marker.lowerUnbounded(BIGINT);
    assertEquals(marker, mapper.readValue(mapper.writeValueAsString(marker), Marker.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 12 with ObjectMapperProvider

use of io.airlift.json.ObjectMapperProvider in project presto by prestodb.

the class TestTupleDomain 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(ColumnHandle.class, new JsonDeserializer<ColumnHandle>() {

        @Override
        public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return new ObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
        }
    }).addDeserializer(Type.class, new TestingTypeDeserializer(typeManager)).addSerializer(Block.class, new TestingBlockJsonSerde.Serializer(blockEncodingSerde)).addDeserializer(Block.class, new TestingBlockJsonSerde.Deserializer(blockEncodingSerde)));
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.all();
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
    tupleDomain = TupleDomain.none();
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(A, NullableValue.of(BIGINT, 1L), B, NullableValue.asNull(VARCHAR)));
    assertEquals(tupleDomain, mapper.readValue(mapper.writeValueAsString(tupleDomain), new TypeReference<TupleDomain<ColumnHandle>>() {
    }));
}
Also used : TestingColumnHandle(com.facebook.presto.spi.TestingColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TestingBlockEncodingSerde(com.facebook.presto.spi.block.TestingBlockEncodingSerde) IOException(java.io.IOException) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(com.facebook.presto.spi.TestingColumnHandle) Type(com.facebook.presto.spi.type.Type) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) TestingTypeDeserializer(com.facebook.presto.spi.type.TestingTypeDeserializer) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) Block(com.facebook.presto.spi.block.Block) TestingBlockJsonSerde(com.facebook.presto.spi.block.TestingBlockJsonSerde) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TestingTypeManager(com.facebook.presto.spi.type.TestingTypeManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Aggregations

ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)12 Type (com.facebook.presto.spi.type.Type)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 Test (org.testng.annotations.Test)9 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)8 TestingTypeDeserializer (com.facebook.presto.spi.type.TestingTypeDeserializer)7 TestingTypeManager (com.facebook.presto.spi.type.TestingTypeManager)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 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 TypeDeserializer (com.facebook.presto.type.TypeDeserializer)2 TypeRegistry (com.facebook.presto.type.TypeRegistry)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)2 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)2 JsonCodecFactory (io.airlift.json.JsonCodecFactory)2 ConstantProperty (com.facebook.presto.spi.ConstantProperty)1 GroupingProperty (com.facebook.presto.spi.GroupingProperty)1