[英]Why jackson @JsonAlias Annotation not work with lombok?
When I received JsonFilter object I expected string to be value of string1 or string2 but the value always null.当我收到 JsonFilter object 时,我希望字符串是 string1 或 string2 的值,但该值始终是 null。
So why @JsonAlias not work with lombok?那么为什么@JsonAlias 不能与 lombok 一起使用呢?
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class JsonFilter {
@JsonAlias({"string1", "string2"})
private String string;
}
Lombok dependency龙目岛依赖
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
By default, lombok doesn't copy annotations: you must explicitly instruct it to via onMethod
:默认情况下,lombok 不会复制注释:您必须通过onMethod
明确指示它:
@Getter(onMethod=@__({@JsonAlias({"string1", "string2"})}))
private String string;
I notice there's a lombok config that might offer a global, and therefore better, fix (I haven't tried it):我注意到有一个 lombok 配置可能会提供一个全局的,因此更好的修复(我没有尝试过):
lombok.copyableAnnotations = [com.fasterxml.jackson.annotation.JsonAlias]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.