2

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

Omar Fulla
  • 33
  • 5

1 Answers1

1

Assuming you're using Jackson, you can annotate your JSON property with JsonRawValue:

private Integer id; 
@JsonRawValue
private JSON    queryJson;

If you need to also read the value from JSON, you can do this:

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

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509