找不到类 org.jooq.JSON 的序列化程序,也没有发现用于创建 BeanSerializer 的属性
通过将方法实现为 API 服务,我遇到了这个问题
找不到类 org.jooq.JSON 的序列化程序,也没有属性 发现创建 BeanSerializer (为了避免异常,禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链: java.util.ArrayList[0]-> db.jooq.tables.pojos.Query["queryJson"])
我的查询(表)的 Jooq POJO 是:
private Integer id;
private JSON queryJson;
给出查询列表作为响应的方法是
@Produces(MediaType.APPLICATION_JSON) public Response
getQueries(@PathParam("ownerId") String ownerId,
@PathParam("roomId") String hotelroom) throws JsonProcessingException {
List<Query> queries = DatabaseUtil.getQueries(dsl, UUID.fromString(hotelroom));
return Response.ok(queries).build();}
但是没有序列化,如果我更改 jooq POJO 对此:
private Integer id;
private String queryJson;
那么我的响应的输出将不会通过序列化而出现错误。 有谁知道如何在 jooq 中解决这个问题吗?
By implementing a method as a service for API, I faced this problem
No serializer found for class org.jooq.JSON and no properties
discovered to create BeanSerializer (to avoid exception, disable
SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain:
java.util.ArrayList[0]-> db.jooq.tables.pojos.Query["queryJson"])
The Jooq POJO of my Query (TABLE) is :
private Integer id;
private JSON queryJson;
and the method which give a list of query as a respond is
@Produces(MediaType.APPLICATION_JSON) public Response
getQueries(@PathParam("ownerId") String ownerId,
@PathParam("roomId") String hotelroom) throws JsonProcessingException {
List<Query> queries = DatabaseUtil.getQueries(dsl, UUID.fromString(hotelroom));
return Response.ok(queries).build();}
But there is no serialize and if I change the jooq POJO to this :
private Integer id;
private String queryJson;
Then the output of my response will have no error by serializing.
Does any one have an idea, how to solve this problem in jooq?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用的是 Jackson,您可以使用
JsonRawValue
< 注释您的JSON
属性/a>:如果您还需要从 JSON 读取值,您可以这样做:
... with:
未来的 jOOQ 版本(尚未到 3.16)可能会在代码生成器中为此类注释提供本机支持: https://github.com/jOOQ/jOOQ/issues/13333
Assuming you're using Jackson, you can annotate your
JSON
property withJsonRawValue
:If you need to also read the value from JSON, you can do this:
... with:
A future jOOQ version (not yet 3.16), might offer native support in the code generator for such annotations: https://github.com/jOOQ/jOOQ/issues/13333
您无法在生成的 JOOQ 源中注释字段,因为自定义注释将在下一次代码生成期间被覆盖。
在寻找答案时,我发现 这个博客文章。
总而言之,您需要创建一个自定义序列化程序,使 Jackson 能够了解如何序列化 org.jooq.JSON 对象。
然后通过在您应该已有的任何 Spring
@Configuration
类中添加配置方法来配置 Jackson 以使用它。You cannot annotate fields in the generated JOOQ sources because the custom annotation will be overriden during the next code generation.
While looking for the answer, I found this blog post.
To sum up, you need to create a custom serializer that will allow Jackson to understand how to serialize the
org.jooq.JSON
objects.Then configure the Jackson to use it by adding the configuration method in any of the Spring
@Configuration
classes you should already have.