- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
JsonGeneratorBase
A JSON generator interface for writing JSON data.
This interface provides methods to generate JSON content in a streaming fashion, allowing for efficient writing of large JSON documents without building the entire content in memory first. It supports writing to output streams and writers with automatic JSON formatting.
The generator provides fluent method chaining for building JSON structures and handles proper JSON syntax including quotes, commas, and brackets.
This module is incubating. These APIs may change in any version of Helidon, including backward incompatible changes.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This method does not close the stream it is writing to.static JsonGeneratorcreate(OutputStream outputStream) Create aJsonGeneratorinstance to write to the providedOutputStream.static JsonGeneratorCreate aJsonGeneratorinstance to write to the providedWriter.write(boolean value) Write a boolean value.write(byte value) Write a byte value.write(char value) Write a char value.write(double value) Write a double value.write(float value) Write a float value.write(int value) Write an int value.write(long value) Write a long value.write(short value) Write a short value.Write a JsonValue.Write a string value.Write a key-value pair with a boolean value.Write a key-value pair with a char value.Write a key-value pair with a double value.Write a key-value pair with a float value.Write a key-value pair with an int value.Write a key-value pair with a long value.Write a key-value pair with a JsonValue.Write a key-value pair with a string value.write(String key, BigDecimal value) Write a key-value pair with aBigDecimalvalue.write(String key, BigInteger value) Write a key-value pair with aBigIntegervalue.write(BigDecimal value) Write aBigDecimalvalue.write(BigInteger value) Write aBigIntegervalue.Write the end of a JSON array.Write the start of a JSON array.writeBinary(byte[] value) Write a value in a binary format.writeBinary(String key, byte[] value) Write a key-value pair with a value in a binary format.Write a key value to the output stream.Write a null value.Write the end of a JSON object.Write the start of a JSON object.
-
Method Details
-
create
Create aJsonGeneratorinstance to write to the providedOutputStream.- Parameters:
outputStream- output stream to write to- Returns:
- new Generator instance
-
create
Create aJsonGeneratorinstance to write to the providedWriter.- Parameters:
writer- writer to write to- Returns:
- new Generator instance
-
writeKey
Write a key value to the output stream.Each key will be automatically enclosed with quotes and a colon appended
"key":. This method is used for writing JSON object keys.- Parameters:
key- the key value to write- Returns:
- this generator for method chaining
-
write
Write a key-value pair with a string value.- Parameters:
key- the keyvalue- the string value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with an int value.- Parameters:
key- the keyvalue- the int value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with a long value.- Parameters:
key- the keyvalue- the long value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with a float value.- Parameters:
key- the keyvalue- the float value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with a double value.- Parameters:
key- the keyvalue- the double value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with a boolean value.- Parameters:
key- the keyvalue- the boolean value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with a char value.- Parameters:
key- the keyvalue- the char value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with aBigDecimalvalue.- Parameters:
key- the keyvalue- the decimal value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with aBigIntegervalue.- Parameters:
key- the keyvalue- the big integer value- Returns:
- this generator for method chaining
-
write
Write a key-value pair with a JsonValue.- Parameters:
key- the keyvalue- the JsonValue- Returns:
- this generator for method chaining
-
writeBinary
Write a key-value pair with a value in a binary format.- Parameters:
key- the keyvalue- the binary data value- Returns:
- this generator for method chaining
-
write
Write a string value.- Parameters:
value- the string value- Returns:
- this generator for method chaining
-
write
Write a byte value.- Parameters:
value- the byte value- Returns:
- this generator for method chaining
-
write
Write a short value.- Parameters:
value- the short value- Returns:
- this generator for method chaining
-
write
Write an int value.- Parameters:
value- the int value- Returns:
- this generator for method chaining
-
write
Write a long value.- Parameters:
value- the long value- Returns:
- this generator for method chaining
-
write
Write a float value.- Parameters:
value- the float value- Returns:
- this generator for method chaining
-
write
Write a double value.- Parameters:
value- the double value- Returns:
- this generator for method chaining
-
write
Write a boolean value.- Parameters:
value- the boolean value- Returns:
- this generator for method chaining
-
write
Write a char value.- Parameters:
value- the char value- Returns:
- this generator for method chaining
-
write
Write aBigDecimalvalue.- Parameters:
value- the decimal value- Returns:
- this generator for method chaining
-
write
Write aBigIntegervalue.- Parameters:
value- the big integer value- Returns:
- this generator for method chaining
-
write
Write a JsonValue.- Parameters:
value- the JsonValue to write- Returns:
- this generator for method chaining
-
writeBinary
Write a value in a binary format.- Parameters:
value- the binary data value- Returns:
- this generator for method chaining
-
writeNull
JsonGenerator writeNull()Write a null value.- Returns:
- this generator for method chaining
-
writeArrayStart
JsonGenerator writeArrayStart()Write the start of a JSON array.- Returns:
- this generator for method chaining
-
writeArrayEnd
JsonGenerator writeArrayEnd()Write the end of a JSON array.- Returns:
- this generator for method chaining
-
writeObjectStart
JsonGenerator writeObjectStart()Write the start of a JSON object.- Returns:
- this generator for method chaining
-
writeObjectEnd
JsonGenerator writeObjectEnd()Write the end of a JSON object.- Returns:
- this generator for method chaining
-
close
void close()This method does not close the stream it is writing to. It only performs final writing operations.- Specified by:
closein interfaceAutoCloseable
-