public class JSON extends AbstractConverter implements IncludeExcludeConverter
A converter that converts domain classes, Maps, Lists, Arrays, POJOs and POGOs to JSON.
Modifiers | Name | Description |
---|---|---|
class |
JSON.Builder |
Modifiers | Name | Description |
---|---|---|
protected CircularReferenceBehaviour |
circularReferenceBehaviour |
|
protected ConverterConfiguration<JSON> |
config |
|
protected boolean |
prettyPrint |
|
protected Stack<Object> |
referenceStack |
|
protected Object |
target |
|
protected JSONWriter |
writer |
Fields inherited from class | Fields |
---|---|
class AbstractConverter |
contentType, encoding, excludes, includes |
Type Params | Return Type | Name and description |
---|---|---|
|
public void |
build(Closure c) |
|
public void |
convertAnother(Object o) |
|
public static void |
createNamedConfig(String name, Closure<?> callable) |
|
public int |
getDepth() |
|
public static ConverterConfiguration<JSON> |
getNamedConfig(String configName) |
|
public JSONWriter |
getWriter() |
|
protected void |
handleCircularRelationship(Object o) |
|
protected ConverterConfiguration<JSON> |
initConfig() |
|
public ObjectMarshaller<JSON> |
lookupObjectMarshaller(Object target) |
|
public static JSONElement |
parse(Reader reader) Parses the given JSON String and returns either a JSONObject or a JSONArray |
|
public static JSONElement |
parse(String source) Parses the given JSON String and returns either a JSONObject or a JSONArray |
|
public static JSONElement |
parse(InputStream is, String encoding) Parses the given JSON and returns either a JSONObject or a JSONArray |
|
public static Object |
parse(HttpServletRequest request) Parses the given request's InputStream and returns either a JSONObject or a JSONArray |
|
public void |
property(String key, Object value) |
|
public static void |
registerObjectMarshaller(Class<?> clazz, Closure<?> callable) |
|
public static void |
registerObjectMarshaller(Class<?> clazz, int priority, Closure<?> callable) |
|
public static void |
registerObjectMarshaller(ObjectMarshaller<JSON> om) |
|
public static void |
registerObjectMarshaller(ObjectMarshaller<JSON> om, int priority) |
|
public void |
render(Writer out) Directs the JSON Writer to the given Writer |
|
public void |
render(HttpServletResponse response) Directs the JSON Writer to the Outputstream of the HttpServletResponse and sets the Content-Type to application/json |
|
public void |
setExcludes(List<String> excludes) |
|
public void |
setIncludes(List<String> includes) |
|
public void |
setPrettyPrint(boolean prettyPrint) |
|
public void |
setTarget(Object target) Sets the Object which is later converted to JSON |
|
public String |
toString(boolean prettyPrint) Performs the conversion and returns the resulting JSON as String |
|
public static Object |
use(String configName, Closure<?> callable) |
|
public static void |
use(String cfgName) |
|
public void |
value(Object o)
|
|
public static void |
withDefaultConfiguration(Closure<?> callable) |
Methods inherited from class | Name |
---|---|
class AbstractConverter |
createBeanWrapper, getExcludes, getIncludes, setContentType, setEncoding, setExcludes, setIncludes, setTarget, toString, writeTo |
Default Constructor for a JSON Converter
Creates a new JSON Converter for the given Object
target
- the Object to convertParses the given JSON String and returns either a JSONObject or a JSONArray
reader
- JSON sourceParses the given JSON String and returns either a JSONObject or a JSONArray
source
- A string containing some JSONParses the given JSON and returns either a JSONObject or a JSONArray
is
- An InputStream which delivers some JSONencoding
- the Character Encoding to useParses the given request's InputStream and returns either a JSONObject or a JSONArray
request
- the JSON RequestDirects the JSON Writer to the given Writer
out
- the WriterDirects the JSON Writer to the Outputstream of the HttpServletResponse and sets the Content-Type to application/json
response
- a HttpServletResponseSets the Object which is later converted to JSON
target
- the ObjectPerforms the conversion and returns the resulting JSON as String
prettyPrint
- true, if the output should be indented, otherwise false