Search in sources :

Example 1 with DeserializationConfig

use of com.fasterxml.jackson.databind.DeserializationConfig in project autorest-clientruntime-for-java by Azure.

the class FlatteningDeserializer method getModule.

/**
 * Gets a module wrapping this serializer as an adapter for the Jackson
 * ObjectMapper.
 *
 * @param mapper the object mapper for default deserializations
 * @return a simple module to be plugged onto Jackson ObjectMapper.
 */
public static SimpleModule getModule(final ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {

        @Override
        public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) {
            if (beanDesc.getBeanClass().getAnnotation(JsonFlatten.class) != null) {
                return new FlatteningDeserializer(beanDesc.getBeanClass(), deserializer, mapper);
            }
            return deserializer;
        }
    });
    return module;
}
Also used : 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) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 2 with DeserializationConfig

use of com.fasterxml.jackson.databind.DeserializationConfig in project Activiti by Activiti.

the class CommonModelAutoConfiguration method customizeCommonModelObjectMapper.

// this bean will be automatically injected inside boot's ObjectMapper
@Bean
public Module customizeCommonModelObjectMapper() {
    SimpleModule module = new SimpleModule("mapCommonModelInterfaces", Version.unknownVersion());
    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver() {

        // this is a workaround for https://github.com/FasterXML/jackson-databind/issues/2019
        // once version 2.9.6 is related we can remove this @override method
        @Override
        public JavaType resolveAbstractType(DeserializationConfig config, BeanDescription typeDesc) {
            return findTypeMapping(config, typeDesc.getType());
        }
    };
    resolver.addMapping(VariableInstance.class, VariableInstanceImpl.class);
    module.setAbstractTypes(resolver);
    module.setMixInAnnotation(Payload.class, PayloadMixIn.class);
    module.setMixInAnnotation(Result.class, ResultMixIn.class);
    module.registerSubtypes(new NamedType(EmptyResult.class, EmptyResult.class.getSimpleName()));
    return module;
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) DeserializationConfig(com.fasterxml.jackson.databind.DeserializationConfig) EmptyResult(org.activiti.api.model.shared.EmptyResult) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) SimpleAbstractTypeResolver(com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver) Bean(org.springframework.context.annotation.Bean)

Example 3 with DeserializationConfig

use of com.fasterxml.jackson.databind.DeserializationConfig in project jackson-databind by FasterXML.

the class TestJDKSerialization method testConfigs.

public void testConfigs() throws IOException {
    byte[] base = jdkSerialize(MAPPER.getDeserializationConfig().getBaseSettings());
    assertNotNull(jdkDeserialize(base));
    // first things first: underlying BaseSettings
    DeserializationConfig origDC = MAPPER.getDeserializationConfig();
    SerializationConfig origSC = MAPPER.getSerializationConfig();
    byte[] dcBytes = jdkSerialize(origDC);
    byte[] scBytes = jdkSerialize(origSC);
    DeserializationConfig dc = jdkDeserialize(dcBytes);
    assertNotNull(dc);
    assertEquals(dc._deserFeatures, origDC._deserFeatures);
    SerializationConfig sc = jdkDeserialize(scBytes);
    assertNotNull(sc);
    assertEquals(sc._serFeatures, origSC._serFeatures);
}
Also used : SerializationConfig(com.fasterxml.jackson.databind.SerializationConfig) DeserializationConfig(com.fasterxml.jackson.databind.DeserializationConfig)

Example 4 with DeserializationConfig

use of com.fasterxml.jackson.databind.DeserializationConfig in project nakadi by zalando.

the class JsonConfig method enumModule.

private SimpleModule enumModule() {
    // see http://stackoverflow.com/questions/24157817/jackson-databind-enum-case-insensitive
    final SimpleModule enumModule = new SimpleModule();
    enumModule.setDeserializerModifier(new BeanDeserializerModifier() {

        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer(final DeserializationConfig config, final JavaType type, final BeanDescription beanDesc, final JsonDeserializer<?> deserializer) {
            return new LowerCaseEnumJsonDeserializer(type);
        }
    });
    enumModule.addSerializer(Enum.class, new LowerCaseEnumJsonSerializer());
    return enumModule;
}
Also used : BeanDeserializerModifier(com.fasterxml.jackson.databind.deser.BeanDeserializerModifier) JavaType(com.fasterxml.jackson.databind.JavaType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) DeserializationConfig(com.fasterxml.jackson.databind.DeserializationConfig) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 5 with DeserializationConfig

use of com.fasterxml.jackson.databind.DeserializationConfig 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

DeserializationConfig (com.fasterxml.jackson.databind.DeserializationConfig)9 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)7 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)7 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)4 BeanDeserializerModifier (com.fasterxml.jackson.databind.deser.BeanDeserializerModifier)4 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)3 SimpleAbstractTypeResolver (com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver)3 Bean (org.springframework.context.annotation.Bean)3 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationConfig (com.fasterxml.jackson.databind.SerializationConfig)1 EmptyResult (org.activiti.api.model.shared.EmptyResult)1 CreateProcessInstancePayload (org.activiti.api.process.model.payloads.CreateProcessInstancePayload)1 DeleteProcessPayload (org.activiti.api.process.model.payloads.DeleteProcessPayload)1 GetProcessDefinitionsPayload (org.activiti.api.process.model.payloads.GetProcessDefinitionsPayload)1 GetProcessInstancesPayload (org.activiti.api.process.model.payloads.GetProcessInstancesPayload)1 GetVariablesPayload (org.activiti.api.process.model.payloads.GetVariablesPayload)1 MessageEventPayload (org.activiti.api.process.model.payloads.MessageEventPayload)1 ReceiveMessagePayload (org.activiti.api.process.model.payloads.ReceiveMessagePayload)1