Provide built-in support for serializing a jOOQ Record to json
See original GitHub issueExpected behavior
Consider a query returning a jOOQ Record
(e.g., CustomerRecord
) and the following Spring Boot REST Controller
:
@GetMapping("/customer")
public CustomerRecord findAnyCustomer() {
return {some_CustomerRecord};
}
Expecting that the default Spring Boot (Jackson based) serializer will output a JSON containing the CustomerRecord
data.
Actual behavior
Initially, it throws an exception: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.jooq.TableOptions and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: jooq.generated.tables.records.CustomerRecord[“table”]->jooq.generated.tables.Customer[“options”])
After setting FAIL_ON_EMPTY_BEANS
in application.properties
I got a relatively big JSON that looks like this fragment:
{“table”:{“name”:“customer”,“comment”:“”,“options”:{},“identity”:{“table”:{“name”:“customer”,“comment”:“”,“options”:{},“identity”:{“table”:{“name”:“customer”,“comment”:" …
Versions
- Spring Boot: 2.3.6.RELEASE
- jOOQ: 3.14.4
- Java: 14 (Spring Boot 2.3.6)
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
Well, a quick draft of letting
Record <: Map<String, Object>
(full comments to be seen here: https://github.com/jOOQ/jOOQ/issues/11889#issuecomment-841134429) yields very promising results:Producing this jOOQ result structure:
And then getting auto serialised by both Jackson and Gson to something like this:
We’re onto something. I think that this is exactly what everyone wants from jOOQ, and Spring Boot doesn’t need to change a thing (I think?) 😀
Sure, greatly appreciated. I still wonder why the perception is different. Habits? People have requested a
Record
representation (e.g. formatting) like this:Kinda like in the old days with Informix, etc.
With that representation, the
Iterable<Entry<String, Object>>
type seems more obvious, and all theMap
goodies, likeMap.forEach(BiConsumer<? super String, ? super Object>)
do, too…Anyway. This issue here is about Spring Boot, and I agree that Spring Boot doesn’t need to take action. jOOQ might: https://github.com/jOOQ/jOOQ/issues/11889, and users already can, via
intoMap()