@Accessors(fluent = true)不适合Jakson
在带有Lombok的Spring Boot应用程序中,我有POJO类accountdto
@Data
@Builder
@Accessors(fluent = true)
public class AccountDTO implements Serializable {
private String identification;
}
我的项目汇编罚款。但是,它在执行中给予例外
com.fasterxml.jackson.databind.exc.invaliddefinitionException:no 为class accountdto找到的序列化器,没有发现创建的属性 豆类器
如果我删除了注释@Accessors(fluent = true)
,则它将正常工作而没有任何问题。
我如何制作Lombok
@Accessors(fluent = true)
和Jackson
一起工作?
In Spring boot application with Lombok, I have pojo class AccountDTO
@Data
@Builder
@Accessors(fluent = true)
public class AccountDTO implements Serializable {
private String identification;
}
My project compiles fine. However, it throws an exception in its execution
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No
serializer found for class AccountDTO and no properties discovered to create
BeanSerializer
if I removed the annotation @Accessors(fluent = true)
, then it will work fine without any problems.
How can i make Lombok
@Accessors(fluent = true)
and Jackson
work together ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近在遇到相同问题的同时偶然发现了这个问题,对我的解决方案是在Lombok生成的Getter上添加显式
@jsonproperty
andotation 使用:@getter(onMethod = @__(@jsonproperty))
。就您而言,班级看起来像这样:
I stumbled on this question recently while encountering the same problem and the solution for me was to add an explicit
@JsonProperty
annotation on the getter generated by Lombok using:@Getter(onMethod = @__(@JsonProperty))
.In your case, the class would look like this:
注释课,其中之一:
Annotation class with one of: