Search in sources :

Example 11 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription in project java-chassis by ServiceComb.

the class JacksonPropertyNodeNameProvider method getJavaBeanPropertyName.

private String getJavaBeanPropertyName(JavaBeanProperty property) {
    ObjectMapper objectMapper = DatabindCodec.mapper();
    JavaType type = objectMapper.constructType(property.getDeclaringClass());
    BeanDescription desc = objectMapper.getSerializationConfig().introspect(type);
    return desc.findProperties().stream().filter(prop -> prop.getInternalName().equals(property.getName())).map(BeanPropertyDefinition::getName).findFirst().orElse(property.getName());
}
Also used : Property(org.hibernate.validator.spi.nodenameprovider.Property) DatabindCodec(io.vertx.core.json.jackson.DatabindCodec) PropertyNodeNameProvider(org.hibernate.validator.spi.nodenameprovider.PropertyNodeNameProvider) JavaBeanProperty(org.hibernate.validator.spi.nodenameprovider.JavaBeanProperty) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) JavaType(com.fasterxml.jackson.databind.JavaType) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) JavaType(com.fasterxml.jackson.databind.JavaType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription in project java-chassis by ServiceComb.

the class ConfigObjectFactory method createProperties.

public List<ConfigObjectProperty> createProperties(Object instance, String prefix, Map<String, Object> parameters) {
    List<ConfigObjectProperty> properties = new ArrayList<>();
    JavaType javaType = TypeFactory.defaultInstance().constructType(instance.getClass());
    BeanDescription beanDescription = JsonUtils.OBJ_MAPPER.getSerializationConfig().introspect(javaType);
    for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
        if (propertyDefinition.getField() == null) {
            continue;
        }
        if (propertyDefinition.getSetter() == null && !propertyDefinition.getField().isPublic()) {
            continue;
        }
        Setter<Object, Object> setter = createObjectSetter(propertyDefinition);
        PriorityProperty<?> priorityProperty = createPriorityProperty(propertyDefinition.getField().getAnnotated(), prefix, parameters);
        setter.set(instance, priorityProperty.getValue());
        properties.add(new ConfigObjectProperty(setter, priorityProperty));
    }
    return properties;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) ArrayList(java.util.ArrayList) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)

Example 13 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription in project java-chassis by ServiceComb.

the class BeanDescriptor method init.

public void init(SerializationConfig serializationConfig, JavaType javaType) {
    this.javaType = javaType;
    BeanDescription beanDescription = serializationConfig.introspect(javaType);
    for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
        PropertyDescriptor propertyDescriptor = new PropertyDescriptor();
        propertyDescriptor.setName(propertyDefinition.getName());
        propertyDescriptor.setJavaType(propertyDefinition.getPrimaryType());
        try {
            propertyDescriptor.setGetter(initGetter(propertyDefinition));
        } catch (Throwable e) {
            LOGGER.error("failed to init getter for field {}:{}", javaType.getRawClass().getName(), propertyDefinition.getName(), e);
        }
        try {
            propertyDescriptor.setSetter(initSetter(propertyDefinition));
        } catch (Throwable e) {
            LOGGER.error("failed to init setter for field {}:{}", javaType.getRawClass().getName(), propertyDefinition.getName(), e);
        }
        propertyDescriptors.put(propertyDefinition.getName(), propertyDescriptor);
    }
}
Also used : BeanDescription(com.fasterxml.jackson.databind.BeanDescription) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)

Example 14 with BeanDescription

use of com.fasterxml.jackson.databind.BeanDescription in project java-chassis by ServiceComb.

the class AbstractOperationGenerator method extractAggregatedParameterGenerators.

protected void extractAggregatedParameterGenerators(Map<String, List<Annotation>> methodAnnotationMap, java.lang.reflect.Parameter methodParameter) {
    JavaType javaType = TypeFactory.defaultInstance().constructType(methodParameter.getParameterizedType());
    BeanDescription beanDescription = Json.mapper().getSerializationConfig().introspect(javaType);
    for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
        if (!propertyDefinition.couldSerialize()) {
            continue;
        }
        Annotation[] annotations = collectAnnotations(propertyDefinition);
        ParameterGenerator propertyParameterGenerator = new ParameterGenerator(method, methodAnnotationMap, propertyDefinition.getName(), annotations, propertyDefinition.getPrimaryType());
        parameterGenerators.add(propertyParameterGenerator);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) ParameterGenerator(org.apache.servicecomb.swagger.generator.ParameterGenerator) Annotation(java.lang.annotation.Annotation)

Example 15 with BeanDescription

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

the class ExtensionSerializer method serializeFields.

private void serializeFields(@SuppressWarnings("rawtypes") Extension bean, JsonGenerator gen, SerializerProvider provider) throws IOException {
    JavaType javaType = provider.constructType(Extension.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)

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