Using JOOQ formatJSON to get column:value pairs

danielc :

I'd like my formatJSON() result to be column:value pairs.

[{"ID":1,"AUTHOR_ID":1,"TITLE":"1984"},{"ID":2,"AUTHOR_ID":1,"TITLE":"Animal Farm"}]

This blog post (https://blog.jooq.org/2018/01/) suggests the result is possible by setting a formatting option flag somewhere, but I am unable to find how to specify that option. I am just getting the default (?) output:

{"fields":[{"schema":"sss","table":"ttt","name":"ccc1","type":"zzz"},{"schema":"sss","table":"ttt","name":"ccc2","type":"zzz"}],"records":[[1,"x"]]}

I am using jOOQ 3.7.0, but can upgrade if needed.

Lukas Eder :

I am using jOOQ 3.7.0, but can upgrade if needed.

There's your answer. Upgrade to 3.9 or more to profit from #5372. You can then call Formattable.formatJSON(JSONFormat) like this:

String json = result.formatJSON(new JSONFormat()
    .header(false)
    .recordFormat(RecordFormat.OBJECT));

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=91073&siteId=1