类com.fasterxml.jackson.databind.introspect.AnnotatedConstructor源码实例Demo

下面列出了怎么用com.fasterxml.jackson.databind.introspect.AnnotatedConstructor的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public boolean hasCreatorAnnotation(Annotated annotated) {
    if (super.hasCreatorAnnotation(annotated)) {
        return true;
    } else if (!(annotated instanceof AnnotatedConstructor)) {
        return false;
    } else {
        AnnotatedConstructor annotatedConstructor = (AnnotatedConstructor) annotated;

        ConstructorProperties properties = getConstructorPropertiesAnnotation(annotatedConstructor);

        if (properties == null) {
            return false;
        } else {
            addJacksonAnnotationsToContructorParameters(annotatedConstructor);
            return true;
        }
    }
}
 
@Override
public boolean hasCreatorAnnotation(final Annotated a) {
  if (!(a instanceof AnnotatedConstructor)) {
    return false;
  }
  final AnnotatedConstructor ctor = (AnnotatedConstructor) a;
  if (ctor.getParameterCount() == 0) {
    return true;
  }
  final AutoMatter.Field field = ctor.getParameter(0).getAnnotation(AutoMatter.Field.class);
  return field != null;
}
 
private void addJacksonAnnotationsToContructorParameters(AnnotatedConstructor annotatedConstructor) {
    ConstructorProperties properties = getConstructorPropertiesAnnotation(annotatedConstructor);
    for (int i = 0; i < annotatedConstructor.getParameterCount(); i++) {
        String name = properties.value()[i];
        AnnotatedParameter parameter = annotatedConstructor.getParameter(i);
        Field field = null;
        try {
            field = annotatedConstructor.getDeclaringClass().getDeclaredField(name);
        } catch (NoSuchFieldException ignored) {
        }
        addJacksonAnnotationsToConstructorParameter(field, parameter, name);
    }
}
 
private ConstructorProperties getConstructorPropertiesAnnotation(AnnotatedConstructor annotatedConstructor) {
    Constructor<?> constructor = annotatedConstructor.getAnnotated();
    return constructor.getAnnotation(ConstructorProperties.class);
}
 
 类方法
 同包方法