Search in sources :

Example 1 with MethodProperty

use of com.fasterxml.jackson.databind.deser.impl.MethodProperty in project jackson-module-afterburner by FasterXML.

the class DeserializerModifier method findOptimizableProperties.

/*
    /********************************************************************** 
    /* Internal methods
    /********************************************************************** 
     */
protected List<OptimizedSettableBeanProperty<?>> findOptimizableProperties(DeserializationConfig config, PropertyMutatorCollector collector, Iterator<SettableBeanProperty> propIterator) {
    ArrayList<OptimizedSettableBeanProperty<?>> newProps = new ArrayList<OptimizedSettableBeanProperty<?>>();
    // Ok, then, find any properties for which we could generate accessors
    while (propIterator.hasNext()) {
        SettableBeanProperty prop = propIterator.next();
        AnnotatedMember member = prop.getMember();
        Member jdkMember = member.getMember();
        // if we ever support virtual properties, this would be null, so check, skip
        if (jdkMember == null) {
            continue;
        }
        // First: we can't access private fields or methods....
        if (Modifier.isPrivate(jdkMember.getModifiers())) {
            continue;
        }
        // 30-Jul-2012, tatu: [module-afterburner#6]: Needs to skip custom deserializers, if any.
        if (prop.hasValueDeserializer()) {
            if (!isDefaultDeserializer(prop.getValueDeserializer())) {
                continue;
            }
        }
        if (prop instanceof MethodProperty) {
            // simple setter methods
            Class<?> type = ((AnnotatedMethod) member).getRawParameterType(0);
            if (type.isPrimitive()) {
                if (type == Integer.TYPE) {
                    newProps.add(collector.addIntSetter(prop));
                } else if (type == Long.TYPE) {
                    newProps.add(collector.addLongSetter(prop));
                } else if (type == Boolean.TYPE) {
                    newProps.add(collector.addBooleanSetter(prop));
                }
            } else {
                if (type == String.class) {
                    newProps.add(collector.addStringSetter(prop));
                } else {
                    // any other Object types; we can at least call accessor
                    newProps.add(collector.addObjectSetter(prop));
                }
            }
        } else if (prop instanceof FieldProperty) {
            // be overwritable via Reflection)
            if (Modifier.isFinal(prop.getMember().getMember().getModifiers())) {
                continue;
            }
            Class<?> type = member.getRawType();
            if (type.isPrimitive()) {
                if (type == Integer.TYPE) {
                    newProps.add(collector.addIntField(prop));
                } else if (type == Long.TYPE) {
                    newProps.add(collector.addLongField(prop));
                } else if (type == Boolean.TYPE) {
                    newProps.add(collector.addBooleanField(prop));
                }
            } else {
                if (type == String.class) {
                    newProps.add(collector.addStringField(prop));
                } else {
                    // any other Object types; we can at least call accessor
                    newProps.add(collector.addObjectField(prop));
                }
            }
        }
    }
    return newProps;
}
Also used : FieldProperty(com.fasterxml.jackson.databind.deser.impl.FieldProperty) MethodProperty(com.fasterxml.jackson.databind.deser.impl.MethodProperty) Member(java.lang.reflect.Member)

Example 2 with MethodProperty

use of com.fasterxml.jackson.databind.deser.impl.MethodProperty in project beam by apache.

the class PipelineOptionsFactory method createBeanProperty.

private static BeanProperty createBeanProperty(Method method) {
    AnnotationCollector ac = AnnotationCollector.emptyCollector();
    for (Annotation ann : method.getAnnotations()) {
        ac = ac.addOrOverride(ann);
    }
    AnnotatedMethod annotatedMethod = new AnnotatedMethod(new TypeResolutionContext.Basic(MAPPER.getTypeFactory(), TypeBindings.emptyBindings()), method, ac.asAnnotationMap(), null);
    BeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(MAPPER.getDeserializationConfig(), annotatedMethod);
    JavaType type = MAPPER.constructType(method.getGenericReturnType());
    try {
        return new MethodProperty(propDef, type, MAPPER.getDeserializationConfig().findTypeDeserializer(type), annotatedMethod.getAllAnnotations(), annotatedMethod);
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) AnnotationCollector(com.fasterxml.jackson.databind.introspect.AnnotationCollector) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) TypeResolutionContext(com.fasterxml.jackson.databind.introspect.TypeResolutionContext) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) SimpleBeanPropertyDefinition(com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition) MethodProperty(com.fasterxml.jackson.databind.deser.impl.MethodProperty) Annotation(java.lang.annotation.Annotation)

Aggregations

MethodProperty (com.fasterxml.jackson.databind.deser.impl.MethodProperty)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 FieldProperty (com.fasterxml.jackson.databind.deser.impl.FieldProperty)1 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)1 AnnotationCollector (com.fasterxml.jackson.databind.introspect.AnnotationCollector)1 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)1 TypeResolutionContext (com.fasterxml.jackson.databind.introspect.TypeResolutionContext)1 SimpleBeanPropertyDefinition (com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition)1 Annotation (java.lang.annotation.Annotation)1 Member (java.lang.reflect.Member)1