java.lang.Object
net.luis.utils.io.data.json.JsonWriter
- All Implemented Interfaces:
AutoCloseable
A json writer for writing json elements to an output.
The writer can be used to write json arrays, objects, values and null values.
The writer expects only one json element per output.
The writer can be used to write json arrays, objects, values and null values.
The writer expects only one json element per output.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JsonConfig
The json config used by the writer.private final BufferedWriter
The internal writer used to write the json elements. -
Constructor Summary
ConstructorsConstructorDescriptionJsonWriter
(@NotNull OutputProvider output) Constructs a new json writer with the default configuration.JsonWriter
(@NotNull OutputProvider output, @NotNull JsonConfig config) Constructs a new json writer with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
writeJson
(@NotNull JsonElement json) Writes the given json element to the output.
The json element is written as a string with the configuration of the writer.
-
Field Details
-
config
The json config used by the writer. -
writer
The internal writer used to write the json elements.
-
-
Constructor Details
-
JsonWriter
Constructs a new json writer with the default configuration.- Parameters:
output
- The output to create the writer for- Throws:
NullPointerException
- If the output is null
-
JsonWriter
Constructs a new json writer with the given configuration.- Parameters:
output
- The output to create the writer forconfig
- The configuration to use for the writer- Throws:
NullPointerException
- If the output or the configuration is null
-
-
Method Details
-
writeJson
Writes the given json element to the output.
The json element is written as a string with the configuration of the writer.- Parameters:
json
- The json element to write- Throws:
NullPointerException
- If the json element is nullUncheckedIOException
- If an I/O error occurs
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-