|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.ontopia.topicmaps.utils.jtm.JSONWriter
public class JSONWriter
PUBLIC: A JSON serializer. Take a look at the JSON Homepage for a complete specification of
the format.
The JSONWriter object provides key
, value
and
pair
methods to append JSON key/value pairs. With the
array
and endArray
methods you can create bound
array values, and object
and endObject
methods
allows you to create and bound objects. All of these methods return the
JSONWriter instance, permitting a cascade style. For example,
new JSONWriter(myWriter).object().key("JSON").value("Hello, World!") .endObject();which writes
{"JSON":"Hello, World!"}Note: a default instance of a JSONWriter will prettify the output, i.e. include whitespace and newlines as appropriate. To disable this behaviour, use setPrettify.
Constructor Summary | |
---|---|
JSONWriter(java.io.OutputStream stream)
PUBLIC: Create an JSONWriter that writes to a given OutputStream in UTF-8. |
|
JSONWriter(java.io.OutputStream stream,
java.lang.String encoding)
PUBLIC: Create an JSONWriter that writes to a given OutputStream in the given encoding. |
|
JSONWriter(java.io.Writer out)
PUBLIC: Create an JSONWriter that writes to a given Writer. |
Method Summary | |
---|---|
JSONWriter |
array()
PUBLIC: Begin a new JSON array. |
JSONWriter |
endArray()
PUBLIC: Finish an JSON array. |
JSONWriter |
endObject()
PUBLIC: Finish of an JSON object. |
void |
finish()
PUBLIC: Finish the serialization process, flushes the underlying stream. |
boolean |
isPrettify()
PUBLIC: Returns whether the output from the JSON serializer is being prettified, e.g. |
JSONWriter |
key(java.lang.String key)
PUBLIC: Write out the given key. |
JSONWriter |
object()
PUBLIC: Begin to append a new object. |
JSONWriter |
pair(java.lang.String key,
java.lang.String value)
Write a complete JSON key/value pair to the stream. |
void |
setPrettify(boolean prettify)
PUBLIC: Sets the prettify behaviour of the JSON serializer. |
JSONWriter |
value(java.lang.String value)
Write out the given value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JSONWriter(java.io.OutputStream stream) throws java.io.IOException
stream
- Where the output should be written.
java.io.IOException
public JSONWriter(java.io.OutputStream stream, java.lang.String encoding) throws java.io.IOException
stream
- Where the output should be written.encoding
- The desired character encoding.
java.io.IOException
public JSONWriter(java.io.Writer out)
out
- Where the output should be written.Method Detail |
---|
public boolean isPrettify()
public void setPrettify(boolean prettify)
prettify
- true to enable prettifying of the JSON output,
false to disable it.public void finish() throws java.io.IOException
java.io.IOException
public JSONWriter object() throws java.io.IOException
java.io.IOException
public JSONWriter endObject() throws java.io.IOException
java.io.IOException
public JSONWriter array() throws java.io.IOException
java.io.IOException
public JSONWriter endArray() throws java.io.IOException
java.io.IOException
public JSONWriter key(java.lang.String key) throws java.io.IOException
key
- The key to be written.
java.io.IOException
public JSONWriter value(java.lang.String value) throws java.io.IOException
value
- The value to be written.
java.io.IOException
public JSONWriter pair(java.lang.String key, java.lang.String value) throws java.io.IOException
writer.key("mykey").value("myvalue");
key
- The key to be written.value
- The value to be written.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |