Skip to content
Advertisement

How to write output of JsonGenerator?

I’m attempting to write the output of data generated by JsonGenerator to console using :

JavaScript

From the Java docs – https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/io/StringWriter.html:

getBuffer
public StringBuffer getBuffer()
Return the string buffer itself.
Returns:
StringBuffer holding the current buffer value.

Shouldn’t the current value written to the Json generator be outputted when I use :

JavaScript

Advertisement

Answer

Issue is not closing the generator, updated code :

JavaScript

prints :

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement