org.quickconnectfamily.json
Class JSONOutputStream
java.lang.Object
org.quickconnectfamily.json.JSONStream
org.quickconnectfamily.json.JSONOutputStream
public class JSONOutputStream
- extends JSONStream
The JSONOutputStream class is used when you want to send an object as a JSON string to any type of OutputStream such
as a FileOutputStream or a SocketOutputStream. If you want to generate a JSON string from an object
directly use the JSONUtilities.stringify methods instead.
Attributes inherited from parent classes are also included in the JSON string.
- Example 1 Object: An ArrayList with three values: a String "1", a String "hello", and a HashMap
as the third value in the ArrayList. This HashMap has two key/value pairs: "name"/"fred" and "age"/"23".
- Example 1 JSON result: ["1", "hello", {"name":"fred","age":"23"}]
- Example 2 Object: A HashMap with three key/value pairs: "state"/"Idaho", "city"/"Rexburg", and
"people"/ArrayList. The ArrayList that is the value for the "people" key has two String values
"bob" and "sue".
- Example 2 JSON result: {"state":"Idaho", "city":"Rexburg", "people":["bob","sue"]}
While these examples only show two levels of depth your Objects can go to any attribute depth level. You
can have any combination of Java objects as attributes.
Restrictions
The Java object from which the JSON string is being generated can not be a raw Object. I can be anything that inherits from Object.
The Java object from which the JSON string is being generated can not inherit from java.awt.container.
- Author:
- Lee S. Barney
Method Summary |
void |
close()
Closes the output stream and the underlying stream |
void |
writeObject(java.io.Serializable aSerializableObject)
Writes a Serializable Object to the underlying stream as a JSON string |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JSONOutputStream
public JSONOutputStream(java.io.OutputStream aStream)
- Parameters:
aStream
- - the stream to which the JSON is to be written
writeObject
public void writeObject(java.io.Serializable aSerializableObject)
throws JSONException
- Writes a Serializable Object to the underlying stream as a JSON string
- Parameters:
aSerializableObject
- - any Serializable object other than a raw Java Object and anything that inherits from java.awt.container
- Throws:
JSONException
close
public void close()
- Closes the output stream and the underlying stream