Search in sources :

Example 6 with JsonDeserializer

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

the class TestLocalProperties method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    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);
        }
    }));
    TestingColumnHandle columnHandle = new TestingColumnHandle("a");
    LocalProperty<ColumnHandle> property1 = new ConstantProperty<>(columnHandle);
    assertEquals(property1, mapper.readValue(mapper.writeValueAsString(property1), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
    LocalProperty<ColumnHandle> property2 = new SortingProperty<>(columnHandle, SortOrder.ASC_NULLS_FIRST);
    assertEquals(property2, mapper.readValue(mapper.writeValueAsString(property2), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
    LocalProperty<ColumnHandle> property3 = new GroupingProperty<>(ImmutableList.of(columnHandle));
    assertEquals(property3, mapper.readValue(mapper.writeValueAsString(property3), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TestingColumnHandle(com.facebook.presto.sql.planner.TestingColumnHandle) ConstantProperty(com.facebook.presto.spi.ConstantProperty) GroupingProperty(com.facebook.presto.spi.GroupingProperty) SortingProperty(com.facebook.presto.spi.SortingProperty) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(com.facebook.presto.sql.planner.TestingColumnHandle) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Example 7 with JsonDeserializer

use of com.fasterxml.jackson.databind.JsonDeserializer in project web3sdk by FISCO-BCOS.

the class ObjectMapperFactory method configureObjectMapper.

private static ObjectMapper configureObjectMapper(ObjectMapper objectMapper, boolean shouldIncludeRawResponses) {
    if (shouldIncludeRawResponses) {
        SimpleModule module = new SimpleModule();
        module.setDeserializerModifier(new BeanDeserializerModifier() {

            @Override
            public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
                if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) {
                    return new RawResponseDeserializer(deserializer);
                }
                return deserializer;
            }
        });
        objectMapper.registerModule(module);
    }
    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return objectMapper;
}
Also used : Response(org.bcos.web3j.protocol.core.Response) BeanDeserializerModifier(com.fasterxml.jackson.databind.deser.BeanDeserializerModifier) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) DeserializationConfig(com.fasterxml.jackson.databind.DeserializationConfig) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) RawResponseDeserializer(org.bcos.web3j.protocol.deserializer.RawResponseDeserializer) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)3 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)3 Test (org.junit.Test)3 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 NopAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector)2 SimpleSerializers (com.fasterxml.jackson.databind.module.SimpleSerializers)2 Serializers (com.fasterxml.jackson.databind.ser.Serializers)2 ClassSerializer (com.fasterxml.jackson.databind.ser.std.ClassSerializer)2 NumberSerializer (com.fasterxml.jackson.databind.ser.std.NumberSerializer)2 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)2 HashMap (java.util.HashMap)2 Test (org.testng.annotations.Test)2 ConstantProperty (com.facebook.presto.spi.ConstantProperty)1 GroupingProperty (com.facebook.presto.spi.GroupingProperty)1 SortingProperty (com.facebook.presto.spi.SortingProperty)1 TestingColumnHandle (com.facebook.presto.spi.TestingColumnHandle)1