com.ibm.portal.streaming.json
Interface JsonContentHandler

All Known Subinterfaces:
DefaultJsonContentHandler, JsonContentHandlerEx, JsonDocumentContentHandler

public interface JsonContentHandler

Content handler that defines events for JSON data structures. This interface can be used to both generate and parse JSON data. It is modelled after the ContentHandler interface. For JSON generation is it more convenient to use the DefaultJsonContentHandler wrapper. For JSON parsing consider to subclass your parser from EmptyJsonContentHandler.

The JSON data is represented as a stream of events. The events begin with startDocument() and end with endDocument(). Each JSON data type is represented by a startXXX event, followed by the content, followed by an endXXX event. For objects and arrays these events may be nested.

String values are represented as callbacks to the value(char[], int, int) method. Depending on the size of the string, there might be multiple calls to represent a single value. String values are always sent in their unescaped format.

Example: The following JSON structure

 {
     "Image": {
         "Height": 600,
         "Width": 800,
         "Title": "View from 15th Floor",
         "Thumbnail": {
             "Height": 125,
             "Url": "http://www.example.com/image/481989943",
             "Width": "100"
         }
     },
     "IDs": [
         116,
         943,
         234,
         38793
     ]
 }
 
is represented via the following events
 startDocument();
 startObject();
 startMember("Image");
 startObject();
 startMember("Width");
 startNumber();
 value(800);
 endNumber();
 endMember();
 startMember("Height");
 startNumber();
 value(600);
 endNumber();
 endMember();
 startMember("Title");
 startString();
 value("View from 15th Floor", .., ..);
 endString();
 endMember();
 startMember("Thumbnail");
 startObject();
 startMember("Url");
 startString();
 value("http://www.example.com/image/481989943", .., ..);
 endString();
 endMember();
 startMember("Height");
 startNumber();
 value(125);
 endNumber();
 endMember();
 startMember("Width");
 startString();
 value("100", .., ..);
 endString();
 endMember();           
 endObject();
 endMember();
 startMember("IDs");
 startArray();
 startNumber();
 value(116);
 endNumber();
 startNumber();
 value(943);
 endNumber();
 startNumber();
 value(234);
 endNumber();
 startNumber();
 value(38793);
 endNumber();
 endArray();
 endMember();           
 endObject();
 endMember();
 endObject();
 endDocument();
 

See Also:
DefaultJsonContentHandler, EmptyJsonContentHandler
Note:
This interface is designed to be implemented by clients.

Method Summary
 void endArray()
          Indicates the end of an array
 void endBoolean()
          Indicates the end of a boolean value
 void endDocument()
          Indicates the end of the event sequence
 void endMember()
          Indicates the end of a member inside an object
 void endNull()
          Indicates the end of the null token
 void endNumber()
          Indicates the end of a numerical value
 void endObject()
          Indicates the end of an object
 void endString()
          Indicates the end of a string based value
 void startArray()
          Indicates the start of an array
 void startBoolean()
          Indicates the start of a boolean value
 void startDocument()
          Indicates the start of the event sequence
 void startMember(java.lang.String name)
          Indicates the start of a member inside an object
 void startNull()
          Indicates the start of the null token
 void startNumber()
          Indicates the start of a numerical value, either of integer or floating type
 void startObject()
          Indicates the start of an object
 void startString()
          Indicates the start of a string based value
 void value(boolean value)
          Writes a boolean value
 void value(char[] cbuf, int off, int len)
          Streams the content of a string value in its unescaped form
 void value(double value)
          Writes a floating value
 void value(long value)
          Writes an integer value
 

Method Detail

endArray

void endArray()
              throws java.io.IOException
Indicates the end of an array

Throws:
java.io.IOException

endBoolean

void endBoolean()
                throws java.io.IOException
Indicates the end of a boolean value

Throws:
java.io.IOException

endDocument

void endDocument()
                 throws java.io.IOException
Indicates the end of the event sequence

Throws:
java.io.IOException

endMember

void endMember()
               throws java.io.IOException
Indicates the end of a member inside an object

Throws:
java.io.IOException

endNull

void endNull()
             throws java.io.IOException
Indicates the end of the null token

Throws:
java.io.IOException

endNumber

void endNumber()
               throws java.io.IOException
Indicates the end of a numerical value

Throws:
java.io.IOException

endObject

void endObject()
               throws java.io.IOException
Indicates the end of an object

Throws:
java.io.IOException

endString

void endString()
               throws java.io.IOException
Indicates the end of a string based value

Throws:
java.io.IOException

startArray

void startArray()
                throws java.io.IOException
Indicates the start of an array

Throws:
java.io.IOException

startBoolean

void startBoolean()
                  throws java.io.IOException
Indicates the start of a boolean value

Throws:
java.io.IOException

startDocument

void startDocument()
                   throws java.io.IOException
Indicates the start of the event sequence

Throws:
java.io.IOException

startMember

void startMember(java.lang.String name)
                 throws java.io.IOException
Indicates the start of a member inside an object

Parameters:
name - name of the member in its unescaped form, not null
Throws:
java.io.IOException

startNull

void startNull()
               throws java.io.IOException
Indicates the start of the null token

Throws:
java.io.IOException

startNumber

void startNumber()
                 throws java.io.IOException
Indicates the start of a numerical value, either of integer or floating type

Throws:
java.io.IOException

startObject

void startObject()
                 throws java.io.IOException
Indicates the start of an object

Throws:
java.io.IOException

startString

void startString()
                 throws java.io.IOException
Indicates the start of a string based value

Throws:
java.io.IOException

value

void value(boolean value)
           throws java.io.IOException
Writes a boolean value

Parameters:
value - the boolean
Throws:
java.io.IOException

value

void value(char[] cbuf,
           int off,
           int len)
           throws java.io.IOException
Streams the content of a string value in its unescaped form

Parameters:
cbuf - character buffer holding the data, not null
off - index of the first valid character in the buffer
len - length of the valid sequence
Throws:
java.io.IOException

value

void value(double value)
           throws java.io.IOException
Writes a floating value

Parameters:
value - the value, not NaN nor Infinity
Throws:
java.io.IOException

value

void value(long value)
           throws java.io.IOException
Writes an integer value

Parameters:
value - the integer
Throws:
java.io.IOException