Search in sources :

Example 46 with BeanDescription

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

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

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