Search in sources :

Example 6 with AnnotatedField

use of com.fasterxml.jackson.databind.introspect.AnnotatedField in project jackson-module-afterburner by FasterXML.

the class PropertyAccessorCollector method _addFieldsUsingIf.

private <T extends OptimizedBeanPropertyWriter<T>> void _addFieldsUsingIf(MethodVisitor mv, List<T> props, int returnOpcode) {
    // load second arg (index)
    mv.visitVarInsn(ILOAD, 2);
    Label next = new Label();
    // first: check if 'index == 0'
    // "if not zero, goto L (skip stuff)"
    mv.visitJumpInsn(IFNE, next);
    // first field accessor
    // load local for cast bean
    mv.visitVarInsn(ALOAD, 3);
    AnnotatedField field = (AnnotatedField) props.get(0).getMember();
    mv.visitFieldInsn(GETFIELD, beanClassName, field.getName(), Type.getDescriptor(field.getRawType()));
    mv.visitInsn(returnOpcode);
    // And from this point on, loop a bit
    for (int i = 1, end = props.size() - 1; i <= end; ++i) {
        mv.visitLabel(next);
        // No need to check index for the last one
        if (i < end) {
            next = new Label();
            // load second arg (index)
            mv.visitVarInsn(ILOAD, 2);
            mv.visitInsn(ALL_INT_CONSTS[i]);
            mv.visitJumpInsn(IF_ICMPNE, next);
        }
        // load bean
        mv.visitVarInsn(ALOAD, 3);
        field = (AnnotatedField) props.get(i).getMember();
        mv.visitFieldInsn(GETFIELD, beanClassName, field.getName(), Type.getDescriptor(field.getRawType()));
        mv.visitInsn(returnOpcode);
    }
}
Also used : AnnotatedField(com.fasterxml.jackson.databind.introspect.AnnotatedField)

Example 7 with AnnotatedField

use of com.fasterxml.jackson.databind.introspect.AnnotatedField in project jackson-module-afterburner by FasterXML.

the class PropertyAccessorCollector method _addFieldsUsingSwitch.

private <T extends OptimizedBeanPropertyWriter<T>> void _addFieldsUsingSwitch(MethodVisitor mv, List<T> props, int returnOpcode) {
    // load second arg (index)
    mv.visitVarInsn(ILOAD, 2);
    Label[] labels = new Label[props.size()];
    for (int i = 0, len = labels.length; i < len; ++i) {
        labels[i] = new Label();
    }
    Label defaultLabel = new Label();
    mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels);
    for (int i = 0, len = labels.length; i < len; ++i) {
        mv.visitLabel(labels[i]);
        // load bean
        mv.visitVarInsn(ALOAD, 3);
        AnnotatedField field = (AnnotatedField) props.get(i).getMember();
        mv.visitFieldInsn(GETFIELD, beanClassName, field.getName(), Type.getDescriptor(field.getRawType()));
        mv.visitInsn(returnOpcode);
    }
    mv.visitLabel(defaultLabel);
}
Also used : AnnotatedField(com.fasterxml.jackson.databind.introspect.AnnotatedField)

Example 8 with AnnotatedField

use of com.fasterxml.jackson.databind.introspect.AnnotatedField in project jackson-module-afterburner by FasterXML.

the class PropertyMutatorCollector method _addSingleField.

/*
    /**********************************************************
    /* Helper methods, field accessor creation
    /**********************************************************
     */
private void _addSingleField(MethodVisitor mv, OptimizedSettableBeanProperty<?> prop, int loadValueCode, int beanIndex, boolean mustCast) {
    // load second arg (index)
    mv.visitVarInsn(ILOAD, 2);
    // load local for cast bean
    mv.visitVarInsn(ALOAD, beanIndex);
    mv.visitVarInsn(loadValueCode, 3);
    AnnotatedField field = (AnnotatedField) prop.getMember();
    Type type = Type.getType(field.getRawType());
    if (mustCast) {
        mv.visitTypeInsn(CHECKCAST, type.getInternalName());
    }
    mv.visitFieldInsn(PUTFIELD, beanClassName, field.getName(), type.getDescriptor());
    mv.visitInsn(RETURN);
}
Also used : AnnotatedField(com.fasterxml.jackson.databind.introspect.AnnotatedField)

Example 9 with AnnotatedField

use of com.fasterxml.jackson.databind.introspect.AnnotatedField in project jackson-module-afterburner by FasterXML.

the class PropertyMutatorCollector method _addFieldsUsingIf.

private <T extends OptimizedSettableBeanProperty<T>> void _addFieldsUsingIf(MethodVisitor mv, List<T> props, int loadValueCode, int beanIndex, boolean mustCast) {
    // load second arg (index)
    mv.visitVarInsn(ILOAD, 2);
    Label next = new Label();
    // first: check if 'index == 0'
    // "if not zero, goto L (skip stuff)"
    mv.visitJumpInsn(IFNE, next);
    // first field accessor
    // load local for cast bean
    mv.visitVarInsn(ALOAD, beanIndex);
    mv.visitVarInsn(loadValueCode, 3);
    AnnotatedField field = (AnnotatedField) props.get(0).getMember();
    Type type = Type.getType(field.getRawType());
    if (mustCast) {
        mv.visitTypeInsn(CHECKCAST, type.getInternalName());
    }
    mv.visitFieldInsn(PUTFIELD, beanClassName, field.getName(), type.getDescriptor());
    mv.visitInsn(RETURN);
    // And from this point on, loop a bit
    for (int i = 1, end = props.size() - 1; i <= end; ++i) {
        mv.visitLabel(next);
        // No comparison needed for the last entry; assumed to match
        if (i < end) {
            next = new Label();
            // load second arg (index)
            mv.visitVarInsn(ILOAD, 2);
            mv.visitInsn(ALL_INT_CONSTS[i]);
            mv.visitJumpInsn(IF_ICMPNE, next);
        }
        // load bean
        mv.visitVarInsn(ALOAD, beanIndex);
        mv.visitVarInsn(loadValueCode, 3);
        field = (AnnotatedField) props.get(i).getMember();
        type = Type.getType(field.getRawType());
        if (mustCast) {
            mv.visitTypeInsn(CHECKCAST, type.getInternalName());
        }
        mv.visitFieldInsn(PUTFIELD, beanClassName, field.getName(), type.getDescriptor());
        mv.visitInsn(RETURN);
    }
}
Also used : AnnotatedField(com.fasterxml.jackson.databind.introspect.AnnotatedField)

Example 10 with AnnotatedField

use of com.fasterxml.jackson.databind.introspect.AnnotatedField in project jackson-databind by FasterXML.

the class TestAnnotatedClass method testFieldIntrospection.

public void testFieldIntrospection() {
    SerializationConfig config = MAPPER.getSerializationConfig();
    JavaType t = MAPPER.constructType(FieldBean.class);
    AnnotatedClass ac = AnnotatedClass.construct(t, config);
    // AnnotatedClass does not ignore non-visible fields, yet
    assertEquals(2, ac.getFieldCount());
    for (AnnotatedField f : ac.fields()) {
        String fname = f.getName();
        if (!"bar".equals(fname) && !"props".equals(fname)) {
            fail("Unexpected field name '" + fname + "'");
        }
    }
}
Also used : AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) AnnotatedField(com.fasterxml.jackson.databind.introspect.AnnotatedField)

Aggregations

AnnotatedField (com.fasterxml.jackson.databind.introspect.AnnotatedField)11 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)4 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)2 AnnotatedClass (com.fasterxml.jackson.databind.introspect.AnnotatedClass)2 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)2 Parameter (io.swagger.models.parameters.Parameter)2 Annotation (java.lang.annotation.Annotation)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Annotated (com.fasterxml.jackson.databind.introspect.Annotated)1 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)1 AbstractSwaggerExtension (io.swagger.jaxrs.ext.AbstractSwaggerExtension)1 SwaggerExtension (io.swagger.jaxrs.ext.SwaggerExtension)1 AbstractSerializableParameter (io.swagger.models.parameters.AbstractSerializableParameter)1 CookieParameter (io.swagger.models.parameters.CookieParameter)1 FormParameter (io.swagger.models.parameters.FormParameter)1 HeaderParameter (io.swagger.models.parameters.HeaderParameter)1 PathParameter (io.swagger.models.parameters.PathParameter)1