将 Jackson 的 @JsonGetter 与 Lombok 的 @Getter 结合起来

Combine Jackson's @JsonGetter with Lombok's @Getter

我有一些字段用 @Getter/Setter 注释。现在我想在此之上使用 @JsonGetter/JsonSetter 。可以这样做吗,还是我必须写出在它们上使用 Jackson-annotations 的方法?

class C {
     @JsonGetter // Compile error
     @Getter
     private int count;
}

@JsonGetter is method level annotation, so you can only add this annotation for methods, Since 1.5 (deprecated since version 1.5) it is deprecated and recommended to use @JsonProperty

@Target(value=METHOD)
@Retention(value=RUNTIME)
@Deprecated
public @interface JsonGetter

Marker annotation that can be used to define a non-static, no-argument value-returning (non-void) method to be used as a "getter" for a logical property, as an alternative to recommended JsonProperty annotation (which was introduced in version 1.1).