Search in sources :

Example 31 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription in project cxf by apache.

the class JaxRs2Extension method extractParameters.

@SuppressWarnings("deprecation")
@Override
public List<Parameter> extractParameters(final List<Annotation> annotations, final Type type, final Set<Type> typesToSkip, final Iterator<SwaggerExtension> chain) {
    if (shouldIgnoreType(type, typesToSkip)) {
        return new ArrayList<>();
    }
    List<Parameter> parameters = new ArrayList<>();
    for (Annotation annotation : annotations) {
        if (annotation instanceof MatrixParam) {
            MatrixParam param = (MatrixParam) annotation;
            MatrixParameter mp = new MatrixParameter().name(param.value());
            Property schema = createProperty(type);
            if (schema != null) {
                mp.setProperty(schema);
            }
            applyBeanValidatorAnnotations(mp, annotations);
            parameters.add(mp);
        } else if (annotation instanceof BeanParam) {
            // Use Jackson's logic for processing Beans
            final BeanDescription beanDesc = mapper.getSerializationConfig().introspect(constructType(type));
            final List<BeanPropertyDefinition> properties = beanDesc.findProperties();
            for (final BeanPropertyDefinition propDef : properties) {
                final AnnotatedField field = propDef.getField();
                final AnnotatedMethod setter = propDef.getSetter();
                final List<Annotation> paramAnnotations = new ArrayList<>();
                final Iterator<SwaggerExtension> extensions = SwaggerExtensions.chain();
                Type paramType = null;
                // Gather the field's details
                if (field != null) {
                    paramType = field.getAnnotated().getType();
                    for (final Annotation fieldAnnotation : field.annotations()) {
                        if (!paramAnnotations.contains(fieldAnnotation)) {
                            paramAnnotations.add(fieldAnnotation);
                        }
                    }
                }
                // Gather the setter's details but only the ones we need
                if (setter != null) {
                    // Do not set the param class/type from the setter if the values are already identified
                    if (paramType == null && setter.getMember().getGenericParameterTypes() != null) {
                        paramType = setter.getMember().getGenericParameterTypes()[0];
                    }
                    for (final Annotation fieldAnnotation : setter.annotations()) {
                        if (!paramAnnotations.contains(fieldAnnotation)) {
                            paramAnnotations.add(fieldAnnotation);
                        }
                    }
                }
                // Re-process all Bean fields and let the default swagger-jaxrs processor do its thing
                List<Parameter> extracted = extensions.next().extractParameters(paramAnnotations, paramType, typesToSkip, extensions);
                // since downstream processors won't know how to introspect @BeanParam, process here
                for (Parameter param : extracted) {
                    if (ParameterProcessor.applyAnnotations(null, param, paramType, paramAnnotations) != null) {
                        applyBeanValidatorAnnotations(param, paramAnnotations);
                        parameters.add(param);
                    }
                }
            }
        }
    }
    // Only call down to the other items in the chain if no parameters were produced
    if (parameters.isEmpty()) {
        parameters = super.extractParameters(annotations, type, typesToSkip, chain);
    }
    return parameters;
}
Also used : MatrixParam(javax.ws.rs.MatrixParam) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) Type(java.lang.reflect.Type) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) Iterator(java.util.Iterator) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) Parameter(io.swagger.models.parameters.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) AnnotatedField(com.fasterxml.jackson.databind.introspect.AnnotatedField) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) BeanParam(javax.ws.rs.BeanParam)

Example 32 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription in project snow-owl by b2ihealthcare.

the class UsageContextSerializer method serializeFields.

private void serializeFields(@SuppressWarnings("rawtypes") UsageContext bean, JsonGenerator gen, SerializerProvider provider) throws IOException {
    JavaType javaType = provider.constructType(UsageContext.class);
    BeanDescription beanDesc = provider.getConfig().introspect(javaType);
    JsonSerializer<Object> serializer = BeanSerializerFactory.instance.findBeanOrAddOnSerializer(provider, javaType, beanDesc, false);
    serializer.unwrappingSerializer(null).serialize(bean, gen, provider);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription)

Example 33 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription 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 34 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription 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 35 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription 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.fisco.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.fisco.bcos.web3j.protocol.deserializer.RawResponseDeserializer) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

BeanDescription (com.fasterxml.jackson.databind.BeanDescription)47 JavaType (com.fasterxml.jackson.databind.JavaType)25 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)24 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)12 ArrayList (java.util.ArrayList)10 Annotation (java.lang.annotation.Annotation)9 DeserializationConfig (com.fasterxml.jackson.databind.DeserializationConfig)8 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)8 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)7 HashSet (java.util.HashSet)7 SerializationConfig (com.fasterxml.jackson.databind.SerializationConfig)6 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)6 Type (java.lang.reflect.Type)6 LinkedHashMap (java.util.LinkedHashMap)6 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)5 BeanDeserializerModifier (com.fasterxml.jackson.databind.deser.BeanDeserializerModifier)5 JsonSerializer (com.fasterxml.jackson.databind.JsonSerializer)4 BeanSerializerModifier (com.fasterxml.jackson.databind.ser.BeanSerializerModifier)4 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)3