Search in sources :

Example 1 with SimpleAbstractTypeResolver

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

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

the class TypeResolverTest method testSubtypeResolution.

public static void testSubtypeResolution() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
    resolver.addMapping(Map.class, MyMap.class);
    SimpleModule basicModule = new SimpleModule();
    basicModule.setAbstractTypes(resolver);
    mapper.registerModule(basicModule);
    String value = "{\"z\": {\"zz\": {\"a\": 42}}}";
    A a = mapper.readValue(value, A.class);
    Map map = a.getMap();
    assertEquals(MyMap.class, map.getClass());
    Object ob = map.get("zz");
    assertEquals(B.class, ob.getClass());
}
Also used : SimpleAbstractTypeResolver(com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 3 with SimpleAbstractTypeResolver

use of com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver in project Activiti by Activiti.

the class TaskModelAutoConfiguration method customizeTaskModelObjectMapper.

// this bean will be automatically injected inside boot's ObjectMapper
@Bean
public Module customizeTaskModelObjectMapper() {
    SimpleModule module = new SimpleModule("mapTaskRuntimeInterfaces", 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(Task.class, TaskImpl.class);
    resolver.addMapping(TaskCandidateUser.class, TaskCandidateUserImpl.class);
    resolver.addMapping(TaskCandidateGroup.class, TaskCandidateGroupImpl.class);
    module.registerSubtypes(new NamedType(TaskResult.class, TaskResult.class.getSimpleName()));
    module.registerSubtypes(new NamedType(ClaimTaskPayload.class, ClaimTaskPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(CompleteTaskPayload.class, CompleteTaskPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(SaveTaskPayload.class, SaveTaskPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(CreateTaskPayload.class, CreateTaskPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(DeleteTaskPayload.class, DeleteTaskPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(GetTasksPayload.class, GetTasksPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(GetTaskVariablesPayload.class, GetTaskVariablesPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(ReleaseTaskPayload.class, ReleaseTaskPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(UpdateTaskPayload.class, UpdateTaskPayload.class.getSimpleName()));
    module.setAbstractTypes(resolver);
    return module;
}
Also used : ReleaseTaskPayload(org.activiti.api.task.model.payloads.ReleaseTaskPayload) CompleteTaskPayload(org.activiti.api.task.model.payloads.CompleteTaskPayload) CreateTaskPayload(org.activiti.api.task.model.payloads.CreateTaskPayload) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) DeserializationConfig(com.fasterxml.jackson.databind.DeserializationConfig) SimpleAbstractTypeResolver(com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver) GetTaskVariablesPayload(org.activiti.api.task.model.payloads.GetTaskVariablesPayload) TaskResult(org.activiti.api.task.model.results.TaskResult) SaveTaskPayload(org.activiti.api.task.model.payloads.SaveTaskPayload) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) ClaimTaskPayload(org.activiti.api.task.model.payloads.ClaimTaskPayload) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) DeleteTaskPayload(org.activiti.api.task.model.payloads.DeleteTaskPayload) Bean(org.springframework.context.annotation.Bean)

Example 4 with SimpleAbstractTypeResolver

use of com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver in project Activiti by Activiti.

the class ProcessModelAutoConfiguration method customizeProcessModelObjectMapper.

// this bean will be automatically injected inside boot's ObjectMapper
@Bean
public Module customizeProcessModelObjectMapper() {
    SimpleModule module = new SimpleModule("mapProcessModelInterfaces", 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(BPMNActivity.class, BPMNActivityImpl.class);
    resolver.addMapping(ProcessInstance.class, ProcessInstanceImpl.class);
    resolver.addMapping(ProcessDefinition.class, ProcessDefinitionImpl.class);
    resolver.addMapping(BPMNSequenceFlow.class, BPMNSequenceFlowImpl.class);
    resolver.addMapping(IntegrationContext.class, IntegrationContextImpl.class);
    resolver.addMapping(BPMNSignal.class, BPMNSignalImpl.class);
    resolver.addMapping(BPMNTimer.class, BPMNTimerImpl.class);
    resolver.addMapping(BPMNMessage.class, BPMNMessageImpl.class);
    resolver.addMapping(BPMNError.class, BPMNErrorImpl.class);
    resolver.addMapping(MessageSubscription.class, MessageSubscriptionImpl.class);
    resolver.addMapping(StartMessageSubscription.class, StartMessageSubscriptionImpl.class);
    resolver.addMapping(StartMessageDeployedEvent.class, StartMessageDeployedEventImpl.class);
    resolver.addMapping(StartMessageDeploymentDefinition.class, StartMessageDeploymentDefinitionImpl.class);
    module.registerSubtypes(new NamedType(ProcessInstanceResult.class, ProcessInstanceResult.class.getSimpleName()));
    module.registerSubtypes(new NamedType(DeleteProcessPayload.class, DeleteProcessPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(GetProcessDefinitionsPayload.class, GetProcessDefinitionsPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(GetProcessInstancesPayload.class, GetProcessInstancesPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(GetVariablesPayload.class, GetVariablesPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(RemoveProcessVariablesPayload.class, RemoveProcessVariablesPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(SetProcessVariablesPayload.class, SetProcessVariablesPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(SignalPayload.class, SignalPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(TimerPayload.class, TimerPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(StartProcessPayload.class, StartProcessPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(CreateProcessInstancePayload.class, CreateProcessInstancePayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(SuspendProcessPayload.class, SuspendProcessPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(ResumeProcessPayload.class, ResumeProcessPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(UpdateProcessPayload.class, UpdateProcessPayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(StartMessagePayload.class, StartMessagePayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(ReceiveMessagePayload.class, ReceiveMessagePayload.class.getSimpleName()));
    module.registerSubtypes(new NamedType(MessageEventPayload.class, MessageEventPayload.class.getSimpleName()));
    module.setAbstractTypes(resolver);
    return module;
}
Also used : MessageEventPayload(org.activiti.api.process.model.payloads.MessageEventPayload) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) StartMessagePayload(org.activiti.api.process.model.payloads.StartMessagePayload) StartProcessPayload(org.activiti.api.process.model.payloads.StartProcessPayload) DeserializationConfig(com.fasterxml.jackson.databind.DeserializationConfig) DeleteProcessPayload(org.activiti.api.process.model.payloads.DeleteProcessPayload) GetProcessInstancesPayload(org.activiti.api.process.model.payloads.GetProcessInstancesPayload) GetVariablesPayload(org.activiti.api.process.model.payloads.GetVariablesPayload) SignalPayload(org.activiti.api.process.model.payloads.SignalPayload) CreateProcessInstancePayload(org.activiti.api.process.model.payloads.CreateProcessInstancePayload) SimpleAbstractTypeResolver(com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver) RemoveProcessVariablesPayload(org.activiti.api.process.model.payloads.RemoveProcessVariablesPayload) ReceiveMessagePayload(org.activiti.api.process.model.payloads.ReceiveMessagePayload) SetProcessVariablesPayload(org.activiti.api.process.model.payloads.SetProcessVariablesPayload) UpdateProcessPayload(org.activiti.api.process.model.payloads.UpdateProcessPayload) ResumeProcessPayload(org.activiti.api.process.model.payloads.ResumeProcessPayload) ProcessInstanceResult(org.activiti.api.process.model.results.ProcessInstanceResult) GetProcessDefinitionsPayload(org.activiti.api.process.model.payloads.GetProcessDefinitionsPayload) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) SuspendProcessPayload(org.activiti.api.process.model.payloads.SuspendProcessPayload) TimerPayload(org.activiti.api.process.model.payloads.TimerPayload) Bean(org.springframework.context.annotation.Bean)

Example 5 with SimpleAbstractTypeResolver

use of com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class SearchResultServletTest method validateResponse.

@SuppressWarnings("deprecation")
private void validateResponse(MockSlingHttpServletResponse response, List<Map<String, String>> expected) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
    resolver.addMapping(ListItem.class, Item.class);
    SimpleModule module = new SimpleModule();
    module.setAbstractTypes(resolver);
    mapper.registerModule(module);
    ListItem[] listItems = mapper.readValue(response.getOutputAsString(), ListItem[].class);
    List<Map<String, String>> actual = new LinkedList<>();
    for (ListItem item : listItems) {
        actual.add(ImmutableMap.of("url", item.getURL(), "title", item.getTitle(), "id", item.getId()));
    }
    assertEquals(expected, actual);
}
Also used : ListItem(com.adobe.cq.wcm.core.components.models.ListItem) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleAbstractTypeResolver(com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) LinkedList(java.util.LinkedList)

Aggregations

SimpleAbstractTypeResolver (com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)5 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)3 DeserializationConfig (com.fasterxml.jackson.databind.DeserializationConfig)3 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)3 Bean (org.springframework.context.annotation.Bean)3 ListItem (com.adobe.cq.wcm.core.components.models.ListItem)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)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 RemoveProcessVariablesPayload (org.activiti.api.process.model.payloads.RemoveProcessVariablesPayload)1