Printing
Blog post from Starburst
In this part of the Bleeding Edge Java series, Jordan Zimmerman explains the process of printing JSON text from a stream of JSON tokens using Java. The approach involves defining a Java interface, `JsonPrinter`, which uses a mapping function that can be passed to the JDK Stream's map() method, converting each JSON token into a string representation through an enhanced switch statement and pattern matching. This implementation leverages Java's deconstruction feature and covers all possible cases of the `JsonToken` hierarchy, removing the need for a default case. The article provides code examples to demonstrate how to serialize a Java record into JSON text using a `JsonSerializer` and `JsonPrinter`, with downloadable files for testing in jshell. This development is part of a broader exploration of Java's latest features and is aimed at improving data performance, aligning with Starburst's recruitment efforts for software engineers.