@Accessors(fluent = true)不适合Jakson

发布于 2025-02-06 04:51:25 字数 561 浏览 3 评论 0原文

在带有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原来是傀儡 2025-02-13 04:51:25

我最近在遇到相同问题的同时偶然发现了这个问题,对我的解决方案是在Lombok生成的Getter上添加显式@jsonproperty andotation 使用:
@getter(onMethod = @__(@jsonproperty))

就您而言,班级看起来像这样:

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

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:

@Data
@Builder
@Accessors(fluent = true)
@Getter(onMethod = @__(@JsonProperty))
public class AccountDTO  implements Serializable {
    private String identification;
}
屋顶上的小猫咪 2025-02-13 04:51:25

注释课,其中之一:

@Getter(onMethod_ = @JsonGetter) 
@Getter(onMethod_ = @JsonProperty)

Annotation class with one of:

@Getter(onMethod_ = @JsonGetter) 
@Getter(onMethod_ = @JsonProperty)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文