|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnu.validator.json.Serializer
public class Serializer
Nested Class Summary | |
---|---|
private static class |
Serializer.State
|
Field Summary | |
---|---|
private boolean |
first
|
private boolean |
hadCallback
|
private List<Serializer.State> |
stack
|
private Writer |
writer
|
Constructor Summary | |
---|---|
Serializer(OutputStream out)
|
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() . |
private void |
charactersImpl(char[] ch,
int start,
int length)
|
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. |
private static Writer |
newOutputStreamWriter(OutputStream out)
|
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. |
private Serializer.State |
peek()
|
private void |
pop()
|
private void |
push(Serializer.State state)
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final List<Serializer.State> stack
private boolean hadCallback
private boolean first
private final Writer writer
Constructor Detail |
---|
public Serializer(OutputStream out)
Method Detail |
---|
private static Writer newOutputStreamWriter(OutputStream out)
private void push(Serializer.State state)
private void pop()
private Serializer.State peek()
public void bool(boolean bool) throws SAXException
JsonHandler
bool
in interface JsonHandler
bool
- the boolean
SAXException
- if bad things happenprivate void charactersImpl(char[] ch, int start, int length) throws IOException
IOException
public void characters(char[] ch, int start, int length) throws 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 read
SAXException
- if bad things happenpublic void endArray() throws SAXException
JsonHandler
endArray
in interface JsonHandler
SAXException
- if bad things happenpublic void endDocument() throws SAXException
JsonHandler
finally
.
endDocument
in interface JsonHandler
SAXException
- if bad things happenpublic void endObject() throws SAXException
JsonHandler
endObject
in interface JsonHandler
SAXException
- if bad things happenpublic void endString() throws SAXException
JsonHandler
endString
in interface JsonHandler
SAXException
- if bad things happenpublic void key(String key) throws 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
)
SAXException
- if bad things happenpublic void number(int number) throws SAXException
JsonHandler
number
in interface JsonHandler
number
- the number
SAXException
- if bad things happenpublic void number(long number) throws SAXException
JsonHandler
number
in interface JsonHandler
number
- the number
SAXException
- if bad things happenpublic void number(float number) throws SAXException
JsonHandler
number
in interface JsonHandler
number
- the number
SAXException
- if bad things happenpublic void number(double number) throws SAXException
JsonHandler
number
in interface JsonHandler
number
- the number
SAXException
- if bad things happenpublic void startArray() throws SAXException
JsonHandler
startArray
in interface JsonHandler
SAXException
- if bad things happenpublic void startDocument(String callback) throws 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.
SAXException
- if bad things happenpublic void startObject() throws SAXException
JsonHandler
startObject
in interface JsonHandler
SAXException
- if bad things happenpublic void startString() throws SAXException
JsonHandler
startString
in interface JsonHandler
SAXException
- if bad things happenpublic void string(String string) throws 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
SAXException
- if bad things happen
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |