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);
}
}
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);
}
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);
}
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);
}
}
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 + "'");
}
}
}
Aggregations