Search in sources :

Example 1 with FieldProperty

use of com.fasterxml.jackson.databind.deser.impl.FieldProperty 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)

Aggregations

FieldProperty (com.fasterxml.jackson.databind.deser.impl.FieldProperty)1 MethodProperty (com.fasterxml.jackson.databind.deser.impl.MethodProperty)1 Member (java.lang.reflect.Member)1