public class Serializer extends java.lang.Object implements JsonHandler
Constructor and Description |
---|
Serializer(java.io.OutputStream out) |
Modifier and Type | Method and Description |
---|---|
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(java.lang.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(java.lang.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(java.lang.String string)
Reports a JSON null on
null and
a string otherwise. |
public void bool(boolean bool) throws org.xml.sax.SAXException
JsonHandler
bool
in interface JsonHandler
bool
- the booleanorg.xml.sax.SAXException
- if bad things happenpublic void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
JsonHandler
startString()
.characters
in interface JsonHandler
ch
- a buffer of UTF-16 code unitsstart
- the first code unit to readlength
- the number of code units to readorg.xml.sax.SAXException
- if bad things happenpublic void endArray() throws org.xml.sax.SAXException
JsonHandler
endArray
in interface JsonHandler
org.xml.sax.SAXException
- if bad things happenpublic void endDocument() throws org.xml.sax.SAXException
JsonHandler
finally
.endDocument
in interface JsonHandler
org.xml.sax.SAXException
- if bad things happenpublic void endObject() throws org.xml.sax.SAXException
JsonHandler
endObject
in interface JsonHandler
org.xml.sax.SAXException
- if bad things happenpublic void endString() throws org.xml.sax.SAXException
JsonHandler
endString
in interface JsonHandler
org.xml.sax.SAXException
- if bad things happenpublic void key(java.lang.String key) throws org.xml.sax.SAXException
JsonHandler
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.)key
in interface JsonHandler
key
- the key for the key-value pair (must not be null
)org.xml.sax.SAXException
- if bad things happenpublic void number(int number) throws org.xml.sax.SAXException
JsonHandler
number
in interface JsonHandler
number
- the numberorg.xml.sax.SAXException
- if bad things happenpublic void number(long number) throws org.xml.sax.SAXException
JsonHandler
number
in interface JsonHandler
number
- the numberorg.xml.sax.SAXException
- if bad things happenpublic void number(float number) throws org.xml.sax.SAXException
JsonHandler
number
in interface JsonHandler
number
- the numberorg.xml.sax.SAXException
- if bad things happenpublic void number(double number) throws org.xml.sax.SAXException
JsonHandler
number
in interface JsonHandler
number
- the numberorg.xml.sax.SAXException
- if bad things happenpublic void startArray() throws org.xml.sax.SAXException
JsonHandler
startArray
in interface JsonHandler
org.xml.sax.SAXException
- if bad things happenpublic void startDocument(java.lang.String callback) throws org.xml.sax.SAXException
JsonHandler
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)
.
startDocument
in interface JsonHandler
callback
- JavaScript callback function name or null
for
pure JSON.org.xml.sax.SAXException
- if bad things happenpublic void startObject() throws org.xml.sax.SAXException
JsonHandler
startObject
in interface JsonHandler
org.xml.sax.SAXException
- if bad things happenpublic void startString() throws org.xml.sax.SAXException
JsonHandler
startString
in interface JsonHandler
org.xml.sax.SAXException
- if bad things happenpublic void string(java.lang.String string) throws org.xml.sax.SAXException
JsonHandler
null
and
a string otherwise.
When the argument is not null
, this method is
shorthand for
startString(); characters(string.toCharArray(), 0, string.length()); endString();
string
in interface JsonHandler
string
- a string or null
org.xml.sax.SAXException
- if bad things happen