jackson @访问器(fluent = true)不适用于Jakson

ijnw1ujt  于 2022-12-18  发布在  其他
关注(0)|答案(1)|浏览(81)

在Lombok的Sping Boot 应用程序中,我使用pojo类AccountDTO

@Data
@Builder
@Accessors(fluent = true)
public class AccountDTO  implements Serializable {
    private String identification;
}

我的项目编译得很好。但是,它在执行过程中抛出了异常
定义无效异常:未找到类AccountDTO的序列化程序,也未找到用于创建BeanSerializer的属性
如果我删除了注解@Accessors(fluent = true),那么它将工作正常,没有任何问题。
如何使Lombok@Accessors(fluent = true)Jackson一起工作?

wkftcu5l

wkftcu5l1#

我最近遇到同样的问题时偶然发现了这个问题,对我来说,解决方案是在Lombok生成的getter上添加显式的@JsonProperty注解:@Getter(onMethod = @__(@JsonProperty)) .
在您的示例中,类将如下所示:

@Data
@Builder
@Accessors(fluent = true)
@Getter(onMethod = @__(@JsonProperty))
public class AccountDTO  implements Serializable {
    private String identification;
}

相关问题