public final class JSONWriter extends Object
The JSON output is safe to be rendered directly into a "text/javascript" mimetype resource as all unicode characters that are not supported in JavaScript are encoded in hex \\uXXXX format.
| Constructor and Description |
|---|
JSONWriter(Writer out)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
static String |
encodeJSONString(String s)
Safely encode a JSON string value.
|
static String |
encodeToJSON(Object obj)
Encode a simple Java object structure to JSON text.
|
static void |
encodeToJSON(Object obj,
JSONWriter writer)
Encode a simple Java object structure to JSON text.
|
JSONWriter |
endArray()
End an array structure.
|
JSONWriter |
endObject()
End an object structure.
|
JSONWriter |
endValue()
End a value that was started with startValue()
|
JSONWriter |
startArray()
Start an array structure, the endArray() method must be called later.
|
JSONWriter |
startObject()
Start an object structure, the endObject() method must be called later.
|
JSONWriter |
startValue(String name)
Start a value (outputs just a name key), the endValue() method must be called later.
|
JSONWriter |
writeNullValue()
Output a JSON null value.
|
JSONWriter |
writeNullValue(String name)
Output a JSON null value.
|
JSONWriter |
writeRawValue(RawValue value)
Output a JSON boolean value.
|
JSONWriter |
writeValue(boolean value)
Output a JSON boolean value.
|
JSONWriter |
writeValue(double value)
Output a JSON number value.
|
JSONWriter |
writeValue(float value)
Output a JSON number value.
|
JSONWriter |
writeValue(int value)
Output a JSON number value.
|
JSONWriter |
writeValue(long value)
Output a JSON number value.
|
JSONWriter |
writeValue(String value)
Output a JSON string value.
|
JSONWriter |
writeValue(String name,
boolean value)
Output a JSON boolean name and value pair.
|
JSONWriter |
writeValue(String name,
double value)
Output a JSON number name and value pair.
|
JSONWriter |
writeValue(String name,
float value)
Output a JSON number name and value pair.
|
JSONWriter |
writeValue(String name,
int value)
Output a JSON number name and value pair.
|
JSONWriter |
writeValue(String name,
long value)
Output a JSON number name and value pair.
|
JSONWriter |
writeValue(String name,
String value)
Output a JSON string name and value pair.
|
public JSONWriter(Writer out)
out - The Writer to immediately append values to (no internal buffering)public JSONWriter startArray() throws IOException
IOExceptionpublic JSONWriter endArray() throws IOException
IOExceptionpublic JSONWriter startObject() throws IOException
IOExceptionpublic JSONWriter endObject() throws IOException
IOExceptionpublic JSONWriter startValue(String name) throws IOException
IOExceptionpublic JSONWriter endValue()
public JSONWriter writeValue(String name, String value) throws IOException
IOExceptionpublic JSONWriter writeValue(String name, int value) throws IOException
IOExceptionpublic JSONWriter writeValue(String name, long value) throws IOException
IOExceptionpublic JSONWriter writeValue(String name, float value) throws IOException
IOExceptionpublic JSONWriter writeValue(String name, double value) throws IOException
IOExceptionpublic JSONWriter writeValue(String name, boolean value) throws IOException
IOExceptionpublic JSONWriter writeValue(String value) throws IOException
IOExceptionpublic JSONWriter writeValue(int value) throws IOException
IOExceptionpublic JSONWriter writeValue(long value) throws IOException
IOExceptionpublic JSONWriter writeValue(float value) throws IOException
IOExceptionpublic JSONWriter writeValue(double value) throws IOException
IOExceptionpublic JSONWriter writeValue(boolean value) throws IOException
IOExceptionpublic JSONWriter writeNullValue() throws IOException
IOExceptionpublic JSONWriter writeNullValue(String name) throws IOException
IOExceptionpublic JSONWriter writeRawValue(RawValue value) throws IOException
IOExceptionpublic static String encodeToJSON(Object obj)
Handles standard Java data types such as String, Boolean, Integer, Float, Double, null. Also deals with simple List as JSON Array and Map as JSON Object. Recursively processes lists and maps as needed.
obj - Java object of basic data types or List or Map.public static void encodeToJSON(Object obj, JSONWriter writer) throws IOException
Handles standard Java data types such as String, Boolean, Integer, Float, Double, null. Also deals with simple List as JSON Array and Map as JSON Object. Recursively processes lists and maps as needed.
obj - Java object of basic data types or List or Map.writer - JSONWriter for outputIOExceptionCopyright © 2005–2018 Alfresco Software. All rights reserved.