Search in sources :

Example 31 with BeanPropertyDefinition

use of com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition in project incubator-servicecomb-java-chassis by apache.

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 32 with BeanPropertyDefinition

use of com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition in project incubator-servicecomb-java-chassis by apache.

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)

Aggregations

BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)32 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)24 JavaType (com.fasterxml.jackson.databind.JavaType)21 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 ArrayList (java.util.ArrayList)10 Annotation (java.lang.annotation.Annotation)8 Type (java.lang.reflect.Type)6 HashSet (java.util.HashSet)6 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)5 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)3 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)3 SerializationConfig (com.fasterxml.jackson.databind.SerializationConfig)3 AnnotatedField (com.fasterxml.jackson.databind.introspect.AnnotatedField)3 AnnotatedMember (com.fasterxml.jackson.databind.introspect.AnnotatedMember)3 POJOPropertyBuilder (com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 JsonIdentityInfo (com.fasterxml.jackson.annotation.JsonIdentityInfo)2