public class JsonWriter extends Object implements Closeable
object
or
array
structure to an output source.
For example, an empty JSON object can be written as follows:
JsonWriter jsonWriter = new JsonWriter(...);
jsonWriter.writeObject(new JsonObjectBuilder().build());
jsonWriter.close();
It uses JsonGenerator
internally for writing.
The generator is created using one of the Json
's
createGenerator
methodsConstructor and Description |
---|
JsonWriter(OutputStream out)
|
JsonWriter(OutputStream out,
Charset charset)
|
JsonWriter(OutputStream out,
Charset charset,
JsonConfiguration config)
|
JsonWriter(OutputStream out,
JsonConfiguration config)
|
JsonWriter(Writer writer)
|
JsonWriter(Writer writer,
JsonConfiguration config)
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this JSON writer and frees any resources associated with the
writer.
|
void |
write(JsonStructure value)
|
void |
writeArray(JsonArray array)
Writes the specified JSON
array to the output
source. |
void |
writeObject(JsonObject object)
Writes the specified JSON
object to the output
source. |
public JsonWriter(Writer writer)
object
or array
structure to the specified character stream.writer
- to which JSON object or array is writtenpublic JsonWriter(Writer writer, JsonConfiguration config)
object
or array
structure to the specified character stream. The created
writer is configured with the specified configuration.writer
- to which JSON object or array is writtenconfig
- configuration of the writerIllegalArgumentException
- if a feature in the configuration
is not knownpublic JsonWriter(OutputStream out)
object
or array
structure to the specified byte stream. Characters written to
the stream are encoded into bytes using UTF-8 encoding.out
- to which JSON object or array is writtenpublic JsonWriter(OutputStream out, JsonConfiguration config)
object
or array
structure to the specified byte stream. Characters written to
the stream are encoded into bytes using UTF-8 encoding.
The created writer is configured with the specified configuration.out
- to which JSON object or array is writtenconfig
- configuration of the writerIllegalArgumentException
- if a feature in the configuration
is not knownpublic JsonWriter(OutputStream out, Charset charset)
object
or array
structure to the specified byte stream. Characters written to
the stream are encoded into bytes using the specified charset.out
- to which JSON object or array is writtencharset
- a charsetpublic JsonWriter(OutputStream out, Charset charset, JsonConfiguration config)
object
or array
structure to the specified byte stream. Characters written to
the stream are encoded into bytes using the specified charset.
The created writer is configured with the specified configuration.out
- to which JSON object or array is writtencharset
- a charsetconfig
- configuration of the writerIllegalArgumentException
- if a feature in the configuration
is not knownpublic void writeArray(JsonArray array)
array
to the output
source. This method needs to be called only once for a writer instance.array
- JSON array that is to be written to the output sourceJsonException
- if the specified JSON object cannot be
written due to i/o error (IOException would be cause of
JsonException)IllegalStateException
- if this method, writeObject, write or close
method is already calledpublic void writeObject(JsonObject object)
object
to the output
source. This method needs to be called only once for a writer instance.object
- JSON object that is to be written to the output sourceJsonException
- if the specified JSON object cannot be
written due to i/o error (IOException would be cause of JsonException)IllegalStateException
- if this method, writeArray, write or close
method is already calledpublic void write(JsonStructure value)
object
or
array
to the output source. This method needs
to be called only once for a writer instance.value
- JSON array or object that is to be written to the output
sourceJsonException
- if the specified JSON object cannot be
written due to i/o error (IOException would be cause of
JsonException)IllegalStateException
- if this method, writeObject, writeArray
or close method is already calledpublic void close()
close
in interface Closeable
close
in interface AutoCloseable
JsonException
- if an i/o error occurs (IOException would be
cause of JsonException)Copyright © 2013. All Rights Reserved.