Class JSON

java.lang.Object
org.eclipse.jetty.util.ajax.JSON

public class JSON extends Object

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.Convertible 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.Generator may be implemented by classes that know how to render themselves as JSON and the toJSON(Object) method will use JSON.Generator.addJSON(Appendable) to generate the JSON.

The class JSON.Literal may be used to hold pre-generated JSON object.

The interface JSON.Convertor 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.Convertor for that class.

If a JSON object has a x-class field then a direct lookup for a JSON.Convertor for that class name is done (without loading the class).