コード例 #1
0
  public void testSimpleWithType() {
    // first for serialization; should base choice on getter
    POJOPropertiesCollector coll = collector(mapper, TypeTestBean.class, true);
    List<BeanPropertyDefinition> props = coll.getProperties();
    assertEquals(1, props.size());
    assertEquals("value", props.get(0).getName());
    AnnotatedMember m = props.get(0).getAccessor();
    assertTrue(m instanceof AnnotatedMethod);
    assertEquals(Integer.class, m.getRawType());

    // then for deserialization; prefer ctor param
    coll = collector(mapper, TypeTestBean.class, false);
    props = coll.getProperties();
    assertEquals(1, props.size());
    assertEquals("value", props.get(0).getName());
    m = props.get(0).getMutator();
    assertEquals(AnnotatedParameter.class, m.getClass());
    assertEquals(String.class, m.getRawType());
  }
コード例 #2
0
 @Override
 public Object findInjectableValueId(AnnotatedMember m) {
   JacksonInject ann = _findAnnotation(m, JacksonInject.class);
   if (ann == null) {
     return null;
   }
   /* Empty String means that we should use name of declared
    * value class.
    */
   String id = ann.value();
   if (id.length() == 0) {
     // slight complication; for setters, type
     if (!(m instanceof AnnotatedMethod)) {
       return m.getRawType().getName();
     }
     AnnotatedMethod am = (AnnotatedMethod) m;
     if (am.getParameterCount() == 0) {
       return m.getRawType().getName();
     }
     return am.getRawParameterType(0).getName();
   }
   return id;
 }