Alright, fellow Java devs and Vaadin aficionados, let’s talk about something we’ve all(!?) been guilty of at one point: representing DTOs by dumping pretty-printed JSON into our UIs. This is what I have done if I have had Jackson on the classpath:
add(new Pre(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(dto));
Sure, it’s somewhat “readable” (for developers), but let’s be real—it’s far from user-friendly. Our users, and even our fellow developers, deserve better than that. I have been working for Vaadin, a company focusing on (Java) web UIs, and still I have been guilty of this. Sometimes I have used it only as a stepping stone towards a more aesthetic UI, but I have a hobby project where this is the main presentation of the computation. And even Jackson sometimes fails with the above: one might need to handle (circular) references somehow, configure Jackson to support LocalDateTime’s etc.
Let’s be honest with ourselves: maybe we’re doing it wrong.
The data we’re working with can be presented so much more effectively using proper UI components like tables, grids, or other even with some more visual components. It’s more than just a matter of aesthetics—it’s about usability and clarity. That’s why I started building PrettyPrinter as part of the Viritin add-on. It’s a helper that prints data with one liner in a cleaner and friendlier format than JSON.
Check out the small demo here, and start giving your users (and yourself) the UI they deserve.
The first version is out, but I’m very willing to re-iterate with naming and API, I’m sure you have some ideas! The underlying DtoDisplay class already contains some API to also customize the presentation, if you for example wish to make certain properties of a certain type of objects somehow specially formatted. These “property printers” I plan to bring to the PrettyPrinter level (or whatever the final name shall be).
I also plan to prototype with a version of the API (or making this a separate library) that could output raw HTML or preformatted text. I think the whole Java ecosystem would need improvements for this area, even if they didn’t use Vaadin (Flow).