[英]No serializer found for class org.jooq.JSON and no properties discovered to create BeanSerializer
by implementing a method as a service for API, i faced this problem通过为 API 实现一种方法即服务,我遇到了这个问题
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"])
没有找到 class org.jooq.JSON 的序列化程序,也没有发现创建 BeanSerializer 的属性(为避免异常,禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过参考链:java.util.ArrayList[0]-> db.jooq.tables.pojos。查询["queryJson"])
The Jooq POJO of my Query (TABLE) is:我的查询(表)的 Jooq POJO 是:
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:但是没有序列化,如果我将 jooq POJO 更改为:
private Integer id;
private String queryJson;
Then the output of my response will have no error by serializing.那么我的响应的output序列化就没有错误了。 Does any one have an idea, how to solve this problem in jooq
有没有人知道如何在 jooq 中解决这个问题
Assuming you're using Jackson, you can annotate your JSON
property with JsonRawValue
:假设您使用的是 Jackson,您可以使用
JsonRawValue
注释您的JSON
属性:
private Integer id;
@JsonRawValue
private JSON queryJson;
If you need to also read the value from JSON, you can do this:如果您还需要读取 JSON 中的值,您可以这样做:
private Integer id;
@JsonRawValue
@JsonDeserialize(using = JSONDeserializer.class)
private JSON queryJson;
... with: ... 和:
class JSONDeserializer extends JsonDeserializer<JSON> {
@Override
public JSON deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException {
Object t = p.readValueAsTree();
return t == null ? null : JSON.json("" + t);
}
}
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 版本(还不是 3.16)可能会在代码生成器中为此类注释提供本机支持: https://github.com/jOOQ/jOOQ/issues/13333
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.