类级别的注解可以用来定义哪些种类的方法可以被auto-delection
auto-detection表示使用命名习惯或签名模版来查找方法用来数据绑定。例如,被称为"getters"的方法可以通过寻找返回一个值,没有任何参数且具有前缀get在方法名的public的成员方法来auto-detected,
伪值NONE表示所有的auto-detection对于指定的类被禁用,并且注解也适用于其子类,但是仅当解析该类时才有效)。
Pseudo-value ALWAYS表示auto-detection适用于所有的方法类型
默认的值是ALWAYS:这表示,默认的,auto-detection被启用适用于所有的类除非被指示别的
自1.5版本之后,可以使用细粒度的定义,to basically define minimum visibility level needed。Defaults are different for different types(getters需要是public; setters可以是任何访问修饰符,例如)
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE}
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
public @interface JsonAutoDetect{
public enum Visibility{
/*
Value that means that all kinds of access modifiers are acceptable,
from private to public
*/
ANY,
/*
Value that means that any other access modifier other than 'private'
is considered auto-detectable.
*/
NON_PRIVATE,
/*
Value that means access modifiers 'protected' and 'public' are auto-detectable
(and 'private' and 'package access' == no modifiers are not)
*/
PROTECTED_AND_PUBLIC,
/*
Value to indicate that only 'public' access modifier is considered auto-detectable.
*/
PUBLIC_ONLY,
/*
Value that indicates that no access modifiers are auto-detectable:
this can be used to explicitly disable auto-detection for specified types.
*/
NONE,
/*
Value that indicates that default visibility level(whatever it is, depends on context)
is to be used.This usually means that inherited value(from parent visibility settings) is
to be used.
*/
DEFAULT;
public boolean isVisible(Member m){
switch(this){
case ANY:
return true;
case NONE:
return false;
case NON_PRIVATE:
return !Modifier.isPrivate(m.getMoeifiers());
// fall through to public case:
case PUBLIC_ONLY:
return Modifier.isPublic(m.getModifiers());
default:
return false;
}
}
}
Visibility getterVisibility() default Visibility.DEFAULT;
Visibility isGetterVisibility() default Visibility.DEFAULT;
Visibility setterVisibility() default Visibility.DEFAULT;
Visibility creatorVisibility() default Visibility.DEFAULT;
Visibility fieldVisibility() default Visibility.DEFAULT;
}