Search in sources :

Example 1 with RawResponseDeserializer

use of org.bcos.web3j.protocol.deserializer.RawResponseDeserializer 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

BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 DeserializationConfig (com.fasterxml.jackson.databind.DeserializationConfig)1 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 BeanDeserializerModifier (com.fasterxml.jackson.databind.deser.BeanDeserializerModifier)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 Response (org.bcos.web3j.protocol.core.Response)1 RawResponseDeserializer (org.bcos.web3j.protocol.deserializer.RawResponseDeserializer)1