Search in sources :

Example 6 with BeanPropertyWriter

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

the class TestAccessorGeneration method testSingleIntAccessorGeneration.

/*
    /**********************************************************************
    /* Test methods
    /**********************************************************************
     */
public void testSingleIntAccessorGeneration() throws Exception {
    Method method = Bean1.class.getDeclaredMethod("getX");
    AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null);
    PropertyAccessorCollector coll = new PropertyAccessorCollector(Bean1.class);
    BeanPropertyWriter bpw = new BeanPropertyWriter(SimpleBeanPropertyDefinition.construct(null, annMethod, new PropertyName("x")), annMethod, null, null, null, null, null, false, null);
    coll.addIntGetter(bpw);
    BeanPropertyAccessor acc = coll.findAccessor(null);
    Bean1 bean = new Bean1();
    int value = acc.intGetter(bean, 0);
    assertEquals(bean.getX(), value);
}
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)

Example 7 with BeanPropertyWriter

use of com.fasterxml.jackson.databind.ser.BeanPropertyWriter 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

BeanPropertyWriter (com.fasterxml.jackson.databind.ser.BeanPropertyWriter)7 PropertyName (com.fasterxml.jackson.databind.PropertyName)3 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)3 Method (java.lang.reflect.Method)3 Annotated (com.fasterxml.jackson.databind.introspect.Annotated)1 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)1 PropertyWriter (com.fasterxml.jackson.databind.ser.PropertyWriter)1 VirtualBeanPropertyWriter (com.fasterxml.jackson.databind.ser.VirtualBeanPropertyWriter)1 SimpleBeanPropertyFilter (com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter)1 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)1 StoredAsJson (com.hubspot.rosetta.annotations.StoredAsJson)1 IOException (java.io.IOException)1 Map (java.util.Map)1