Search in sources :

Example 6 with PropertyName

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

the class TestAccessorGeneration method testDualIntAccessorGeneration.

public void testDualIntAccessorGeneration() throws Exception {
    PropertyAccessorCollector coll = new PropertyAccessorCollector(Bean3.class);
    String[] methodNames = new String[] { "getX", "getY", "get3" };
    for (String methodName : methodNames) {
        Method method = Bean3.class.getDeclaredMethod(methodName);
        AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null);
        // should we translate from method name to property name?
        coll.addIntGetter(new BeanPropertyWriter(SimpleBeanPropertyDefinition.construct(null, annMethod, new PropertyName(methodName)), annMethod, null, null, null, null, null, false, null));
    }
    BeanPropertyAccessor acc = coll.findAccessor(null);
    Bean3 bean = new Bean3();
    assertEquals(bean.getX(), acc.intGetter(bean, 0));
    assertEquals(bean.getY(), acc.intGetter(bean, 1));
    assertEquals(bean.get3(), acc.intGetter(bean, 2));
}
Also used : PropertyName(com.fasterxml.jackson.databind.PropertyName) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) Method(java.lang.reflect.Method) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter)

Aggregations

PropertyName (com.fasterxml.jackson.databind.PropertyName)6 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)3 BeanPropertyWriter (com.fasterxml.jackson.databind.ser.BeanPropertyWriter)3 Method (java.lang.reflect.Method)3 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 ObjectIdGenerators (com.fasterxml.jackson.annotation.ObjectIdGenerators)1 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 ObjectIdInfo (com.fasterxml.jackson.databind.introspect.ObjectIdInfo)1 Field (java.lang.reflect.Field)1