|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.json.JsonWriter
public class JsonWriter
A JSON writer that writes a JSON object or
array structure to an output source.
For example, an empty JSON object can be written as follows:
It uses
JsonWriter jsonWriter = new JsonWriter(...);
jsonWriter.writeObject(new JsonBuilder().beginObject().endObject().build());
jsonWriter.close();
JsonGenerator for writing.
The generator is created using one of the Json's
createGenerator methods
| Constructor Summary | |
|---|---|
JsonWriter(OutputStream out)
Creates a JSON writer which can be used to write a JSON object or array
structure to the specified byte stream. |
|
JsonWriter(OutputStream out,
JsonConfiguration config)
Creates a JSON writer which can be used to write a JSON object or array
structure to the specified byte stream. |
|
JsonWriter(OutputStream out,
String encoding)
Creates a JSON writer which can be used to write a JSON object or array
structure to the specified byte stream. |
|
JsonWriter(OutputStream out,
String encoding,
JsonConfiguration config)
Creates a JSON writer which can be used to write a JSON object or array
structure to the specified byte stream. |
|
JsonWriter(Writer writer)
Creates a JSON writer which can be used to write a JSON object or array
structure to the specified character stream. |
|
JsonWriter(Writer writer,
JsonConfiguration config)
Creates a JSON writer which can be used to write a JSON object or array
structure to the specified character stream. |
|
| Method Summary | |
|---|---|
void |
close()
Closes this JSON writer and frees any resources associated with the writer. |
void |
write(JsonStructure value)
Writes the specified JSON object or
array to the output source. |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JsonWriter(Writer writer)
object or array
structure to the specified character stream.
writer - to which JSON object or array is written
public 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 writer
IllegalArgumentException - 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 written
public 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 writer
IllegalArgumentException - if a feature in the configuration
is not known
public JsonWriter(OutputStream out,
String encoding)
object or array
structure to the specified byte stream. Characters written to
the stream are encoded into bytes using the specified encoding.
out - to which JSON object or array is writtenencoding - the name of character
encoding of the stream.
JsonException - if the named encoding is not supported. The
cause of the exception would be
UnsupportedEncodingExceptionCharset
public JsonWriter(OutputStream out,
String encoding,
JsonConfiguration config)
object or array
structure to the specified byte stream. Characters written to
the stream are encoded into bytes using the specified encoding.
The created writer is configured with the specified configuration.
out - to which JSON object or array is writtenencoding - the name of character
encoding of the stream.config - configuration of the writer
JsonException - if the named encoding is not supported. The
cause of the exception would be
UnsupportedEncodingException
IllegalArgumentException - if a feature in the configuration
is not knownCharset| Method Detail |
|---|
public 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 source
JsonException - if the specified JSON object cannot be
written due to i/o error
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 source
JsonException - if the specified JSON object cannot be
written due to i/o error
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
source
JsonException - if the specified JSON object cannot be
written due to i/o error
IllegalStateException - if this method, writeObject, writeArray
or close method is already calledpublic void close()
close in interface Closeable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||