JSON parser and generator.
This class provides methods to convert POJOs to and from JSON notation.
The mapping from JSON to Java is:
object --> Map<String, Object> array --> Object[] number --> Double or Long string --> String null --> null bool --> Boolean
The Java to JSON mapping is:
String --> string Number --> number Map --> object List --> array Array --> array null --> null Boolean--> boolean Object --> string (dubious!)
The interface JSON. may be implemented by classes that
wish to externalize and initialize specific fields to and from JSON objects.
Only directed acyclic graphs of objects are supported.
The interface JSON. may be implemented by classes that
know how to render themselves as JSON and the toJSON(Object) method
will use JSON. to generate the JSON.
The class JSON. may be used to hold pre-generated JSON object.
The interface JSON. may be implemented to provide
converters for objects that may be registered with
addConvertor(Class, Convertor).
These converters are looked up by class, interface and super class by
getConvertor(Class).
If a JSON object has a class field, then a Java class for that
name is loaded and the method convertTo(Class, Map) is used to find
a JSON. for that class.
If a JSON object has a x-class field then a direct lookup for a
JSON. for that class name is done (without loading the class).
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| public static interface | JSON.
JSON Convertible object. |
| public static interface | JSON.
JSON Convertor. |
| public static interface | JSON.
JSON Generator. |
| public static class | JSON.
A Literal JSON generator. |
| public static interface | JSON.
JSON Output class for use by |
| public static class | JSON.
A Reader source for a JSON string. |
| public static interface | JSON.
A generic source for a JSON representation. |
| public static class | JSON.
An in-memory source for a JSON string. |
| Modifier and Type | Field and Description |
|---|---|
| private Function | |
| private final Map | |
| private int | |
| pack-priv static final Logger |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addConvertor(Class<?>
the class the convertor applies to forClass, JSON.the convertor for the class convertorRegisters a |
| public void | addConvertorFor(String
the name of the class the convertor applies to name, JSON.the convertor for the class convertorRegisters a |
| public void | append(Appendable
the buffer to append to buffer, Object the object to convert to JSON object)Appends the given object as JSON to string buffer. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| protected static void | |
| protected JSON | Returns: a JSON instance to parse the object fieldthe field name field)Every time a JSON object field representation |
| protected JSON | Returns: a JSON instance to parse array itemsEvery time a JSON array representation |
| protected Object | |
| private Object | |
| public void | escapeString(Appendable
the buffer to escape the string into buffer, String the string to escape input)Escapes the characters of the given |
| protected void | escapeUnicode(Appendable buffer, char c)
Per JSON specification, unicode characters are by default NOT escaped. |
| public Object | |
| public Object | |
| public Function | |
| protected JSON. | Returns: aJSON. or null if none was found for the classthe class to look up the convertor forClass)Looks up a convertor for a class. |
| public JSON. | Returns: aJSON. or null if none were found.name of the class to look up the convertor name)Looks up a convertor for a class name. |
| public int | getStringBufferSize()
Returns: the initial stringBuffer size to use when creating JSON strings (default 1024) |
| protected Object | |
| protected Object[] | Returns: a new array representing the JSON arraythe size of the array size)
Deprecated
use
setArrayConverter(Function) instead.
Factory method that creates an array when a JSON representation of |
| protected Map | Returns: a new Map representing the JSON objectFactory method that creates a Map when a JSON representation of |
| public Object | |
| public Object | |
| protected Object | |
| public Number | |
| protected Object | |
| protected String | |
| private void | |
| public JSON. | Returns: the convertor for the classthe class the convertor applies to forClass)Unregisters a |
| public JSON. | Returns: the convertor for the classthe name of the class the convertor applies to name)Unregisters a |
| protected void | |
| protected char | |
| public void | setArrayConverter(Function<List<?>, Object>
the function to customize the Java representation of JSON arrays arrayConverter)Sets the function to convert JSON arrays from their default Java
representation, a |
| public void | setStringBufferSize(int
the initial stringBuffer size to use when creating JSON
strings (default 1024) stringBufferSize)
|
| public String |