nu.validator.json
Interface JsonHandler

All Known Implementing Classes:
Serializer

public interface JsonHandler

A SAX-inspired streaming interface for JSON. This interface is biased towards streaming writing whereas SAX is biased towards streaming parsing.

Version:
$Id$
Author:
hsivonen

Method Summary
 void bool(boolean bool)
          Reports a boolean.
 void characters(char[] ch, int start, int length)
          Adds characters to the current string started with startString().
 void endArray()
          Reports the end of an array.
 void endDocument()
          Reports the end of the JSON file.
 void endObject()
          Reports the end of an object.
 void endString()
          Reports the end of a string.
 void key(String key)
          Starts a key-value pair inside an object.
 void number(double number)
          Reports a number.
 void number(float number)
          Reports a number.
 void number(int number)
          Reports a number.
 void number(long number)
          Reports a number.
 void startArray()
          Reports the start of an array.
 void startDocument(String callback)
          Reports the start of the JSON file.
 void startObject()
          Reports the start of an object.
 void startString()
          Reports the start of a string.
 void string(String string)
          Reports a JSON null on null and a string otherwise.
 

Method Detail

startDocument

void startDocument(String callback)
                   throws SAXException
Reports the start of the JSON file. When callback is null, the file is a pure JSON file. With a non-null callback, a JSON value is wrapped in a function call named callback.

Note that the JSON null value is represented as string(null).

Parameters:
callback - JavaScript callback function name or null for pure JSON.
Throws:
SAXException - if bad things happen

endDocument

void endDocument()
                 throws SAXException
Reports the end of the JSON file. Must be called finally.

Throws:
SAXException - if bad things happen

startArray

void startArray()
                throws SAXException
Reports the start of an array.

Throws:
SAXException - if bad things happen

endArray

void endArray()
              throws SAXException
Reports the end of an array.

Throws:
SAXException - if bad things happen

startObject

void startObject()
                 throws SAXException
Reports the start of an object.

Throws:
SAXException - if bad things happen

key

void key(String key)
         throws SAXException
Starts a key-value pair inside an object. The parameter key gives the key and the next reported value is taken to be the value associated with the key. (Hence, there is no need for a corresponding end callback.)

Parameters:
key - the key for the key-value pair (must not be null)
Throws:
SAXException - if bad things happen

endObject

void endObject()
               throws SAXException
Reports the end of an object.

Throws:
SAXException - if bad things happen

startString

void startString()
                 throws SAXException
Reports the start of a string.

Throws:
SAXException - if bad things happen

characters

void characters(char[] ch,
                int start,
                int length)
                throws SAXException
Adds characters to the current string started with startString().

Parameters:
ch - a buffer of UTF-16 code units
start - the first code unit to read
length - the number of code units to read
Throws:
SAXException - if bad things happen

endString

void endString()
               throws SAXException
Reports the end of a string.

Throws:
SAXException - if bad things happen

string

void string(String string)
            throws SAXException
Reports a JSON null on null and a string otherwise.

When the argument is not null, this method is shorthand for

startString();
 characters(string.toCharArray(), 0, string.length());
 endString();

Parameters:
string - a string or null
Throws:
SAXException - if bad things happen

number

void number(int number)
            throws SAXException
Reports a number.

Parameters:
number - the number
Throws:
SAXException - if bad things happen

number

void number(long number)
            throws SAXException
Reports a number.

Parameters:
number - the number
Throws:
SAXException - if bad things happen

number

void number(float number)
            throws SAXException
Reports a number.

Parameters:
number - the number
Throws:
SAXException - if bad things happen

number

void number(double number)
            throws SAXException
Reports a number.

Parameters:
number - the number
Throws:
SAXException - if bad things happen

bool

void bool(boolean bool)
          throws SAXException
Reports a boolean.

Parameters:
bool - the boolean
Throws:
SAXException - if bad things happen