我有一些带@Getter/Setter注释的字段。现在,我想在此之上使用@JsonGetter/JsonSetter。可以这样做吗?还是我必须写出在它们上使用Jackson-annotations的方法?
class C {
@JsonGetter // Compile error
@Getter
private int count;
}发布于 2019-11-09 16:40:29
@JsonGetter是方法级注释,因此您只能为方法添加此注释,因为1.5 (自版本1.5起就不再推荐使用)建议使用@JsonProperty
@Target(value=METHOD)
@Retention(value=RUNTIME)
@Deprecated
public @interface JsonGetter标记注释,可用于定义非静态、无参数值返回(非无效)方法,用作逻辑属性的"getter",以替代推荐的JsonProperty注释(在1.1版中引入)。
https://stackoverflow.com/questions/58781313
复制相似问题