Search code examples
jooq

JOOQ Record toString print a summary instead of ASCII table?


Using JOOQ version 3.13.4

I don't like the ASCII table formatting that the Record.toString() method does.

It's particularly unhelpful in the IDEA debugger view: enter image description here

But I also don't like dumping needless multi-line strings into my prod logs - which I usually avoid doing; partially for obvious speed/size reasons, but also because they're ugly and hard to read in most log viewer apps (CloudWatch etc.)

I found the Github issue that implemented the ASCII table: https://github.com/jOOQ/jOOQ/issues/1806

I know I can write code to customise this, but I'm wondering if there's a simple flag/config I'm missing to get a simple summary (if I ever got around to writing my own, I'll use JSON)?


Solution

  • The current formatted ASCII table is quite useful for most debugging purposes, which include simple println() calls, Eclipse's debugging view (see below), etc. This includes showing only the first 5 records in a Result for a quick overview, and Record classes work the same.

    The feedback from the community has generally been good for these defaults, but if you want to challenge them, try your luck here, and see if your feature request gets community upvotes: https://github.com/jOOQ/jOOQ/issues/new/choose

    Eclipse's variable view:

    enter image description here

    As you can see, with the detail view, it's much less of a problem in Eclipse. I've always found it surprising IntelliJ didn't copy this very useful feature from Eclipse. Maybe, request it?

    I know I can write code to customise this

    I'll document it here nonetheless, as future visitors will no doubt find this useful.

    IntelliJ has a lot of "smartness" in its debugger's variables view, sometimes a bit excessive. For example, an org.jooq.Result just displays its size(), because a Result is a List. I guess it's smart to hedge against excessive efforts if JDK lists are too long, though jOOQ results can handle it, and otherwise it would be possible to display list.subList(0, Math.min(list.size(), 5)) + "...".

    Luckily, you can easily specify your own type renderers in IntelliJ, for example this one:

    enter image description here

    It uses this code to render a jOOQ Record:

    formatJSON(new JSONFormat()
        .header(false)
        .recordFormat(JSONFormat.RecordFormat.OBJECT)
    )
    

    The output might look like this:

    enter image description here

    You might even suggest this as a default to IntelliJ?

    but I'm wondering if there's a simple flag/config I'm missing to get a simple summary (if I ever got around to writing my own, I'll use JSON)?

    No, there isn't, and I doubt that kind of configurability is reasonable. People will start requesting 100s of flags to get their preferred way of debugging, when in fact, this can be very easily achieved in the IDE as shown above.

    Again, you can try your luck with a change request to change it for everyone, but a configuration for this is unlikely to be implemented.