public class JSON extends AbstractConverter<org.codehaus.groovy.grails.web.json.JSONWriter> implements org.codehaus.groovy.grails.web.converters.IncludeExcludeConverter<org.codehaus.groovy.grails.web.json.JSONWriter>
| Modifier and Type | Class and Description |
|---|---|
class |
JSON.Builder |
Converter.CircularReferenceBehaviour| Modifier and Type | Field and Description |
|---|---|
protected Converter.CircularReferenceBehaviour |
circularReferenceBehaviour |
protected ConverterConfiguration<JSON> |
config |
protected boolean |
prettyPrint |
protected java.util.Stack<java.lang.Object> |
referenceStack |
protected java.lang.Object |
target |
protected org.codehaus.groovy.grails.web.json.JSONWriter |
writer |
contentType, encoding, excludes, includesDEFAULT_REQUEST_ENCODING| Constructor and Description |
|---|
JSON()
Default Constructor for a JSON Converter
|
JSON(java.lang.Object target)
Creates a new JSON Converter for the given Object
|
| Modifier and Type | Method and Description |
|---|---|
void |
build(groovy.lang.Closure c) |
void |
convertAnother(java.lang.Object o) |
static void |
createNamedConfig(java.lang.String name,
groovy.lang.Closure<?> callable) |
int |
getDepth() |
static ConverterConfiguration<JSON> |
getNamedConfig(java.lang.String configName) |
org.codehaus.groovy.grails.web.json.JSONWriter |
getWriter() |
protected void |
handleCircularRelationship(java.lang.Object o) |
protected ConverterConfiguration<JSON> |
initConfig() |
ObjectMarshaller<JSON> |
lookupObjectMarshaller(java.lang.Object target) |
static java.lang.Object |
parse(javax.servlet.http.HttpServletRequest request)
Parses the given request's InputStream and returns either a JSONObject or a JSONArray
|
static org.codehaus.groovy.grails.web.json.JSONElement |
parse(java.io.InputStream is,
java.lang.String encoding)
Parses the given JSON and returns either a JSONObject or a JSONArray
|
static org.codehaus.groovy.grails.web.json.JSONElement |
parse(java.io.Reader reader)
Parses the given JSON String and returns either a JSONObject or a JSONArray
|
static org.codehaus.groovy.grails.web.json.JSONElement |
parse(java.lang.String source)
Parses the given JSON String and returns either a JSONObject or a JSONArray
|
void |
property(java.lang.String key,
java.lang.Object value) |
static void |
registerObjectMarshaller(java.lang.Class<?> clazz,
groovy.lang.Closure<?> callable) |
static void |
registerObjectMarshaller(java.lang.Class<?> clazz,
int priority,
groovy.lang.Closure<?> callable) |
static void |
registerObjectMarshaller(ObjectMarshaller<JSON> om) |
static void |
registerObjectMarshaller(ObjectMarshaller<JSON> om,
int priority) |
void |
render(javax.servlet.http.HttpServletResponse response)
Directs the JSON Writer to the Outputstream of the HttpServletResponse and sets the Content-Type to application/json
|
void |
render(java.io.Writer out)
Directs the JSON Writer to the given Writer
|
void |
setExcludes(java.util.List<java.lang.String> excludes) |
void |
setIncludes(java.util.List<java.lang.String> includes) |
void |
setPrettyPrint(boolean prettyPrint) |
void |
setTarget(java.lang.Object target)
Sets the Object which is later converted to JSON
|
java.lang.String |
toString(boolean prettyPrint)
Performs the conversion and returns the resulting JSON as String
|
static void |
use(java.lang.String cfgName) |
static java.lang.Object |
use(java.lang.String configName,
groovy.lang.Closure<?> callable) |
void |
value(java.lang.Object o) |
static void |
withDefaultConfiguration(groovy.lang.Closure<?> callable) |
createBeanWrapper, getExcludes, getIncludes, setContentType, setEncoding, setExcludes, setIncludes, toStringprotected java.lang.Object target
protected final ConverterConfiguration<JSON> config
protected final Converter.CircularReferenceBehaviour circularReferenceBehaviour
protected boolean prettyPrint
protected org.codehaus.groovy.grails.web.json.JSONWriter writer
protected java.util.Stack<java.lang.Object> referenceStack
public JSON()
public JSON(java.lang.Object target)
target - the Object to convertprotected ConverterConfiguration<JSON> initConfig()
public void setPrettyPrint(boolean prettyPrint)
public void render(java.io.Writer out)
throws ConverterException
render in interface Converter<org.codehaus.groovy.grails.web.json.JSONWriter>out - the WriterConverterExceptionpublic void render(javax.servlet.http.HttpServletResponse response)
throws ConverterException
render in interface Converter<org.codehaus.groovy.grails.web.json.JSONWriter>response - a HttpServletResponseConverterExceptionpublic org.codehaus.groovy.grails.web.json.JSONWriter getWriter()
throws ConverterException
getWriter in interface Converter<org.codehaus.groovy.grails.web.json.JSONWriter>ConverterExceptionpublic void convertAnother(java.lang.Object o)
throws ConverterException
convertAnother in interface Converter<org.codehaus.groovy.grails.web.json.JSONWriter>ConverterExceptionpublic void build(groovy.lang.Closure c)
throws ConverterException
build in interface Converter<org.codehaus.groovy.grails.web.json.JSONWriter>ConverterExceptionpublic void value(java.lang.Object o)
throws ConverterException
o - ConverterExceptionpublic ObjectMarshaller<JSON> lookupObjectMarshaller(java.lang.Object target)
lookupObjectMarshaller in interface Converter<org.codehaus.groovy.grails.web.json.JSONWriter>public int getDepth()
public void property(java.lang.String key,
java.lang.Object value)
throws org.codehaus.groovy.grails.web.json.JSONException,
ConverterException
org.codehaus.groovy.grails.web.json.JSONExceptionConverterExceptionpublic java.lang.String toString(boolean prettyPrint)
throws org.codehaus.groovy.grails.web.json.JSONException
prettyPrint - true, if the output should be indented, otherwise falseorg.codehaus.groovy.grails.web.json.JSONExceptionpublic static org.codehaus.groovy.grails.web.json.JSONElement parse(java.io.Reader reader)
throws ConverterException
reader - JSON sourceConverterException - when the JSON content is not validpublic static org.codehaus.groovy.grails.web.json.JSONElement parse(java.lang.String source)
throws ConverterException
source - A string containing some JSONConverterException - when the JSON content is not validpublic static org.codehaus.groovy.grails.web.json.JSONElement parse(java.io.InputStream is,
java.lang.String encoding)
throws ConverterException
is - An InputStream which delivers some JSONencoding - the Character Encoding to useConverterException - when the JSON content is not validpublic static java.lang.Object parse(javax.servlet.http.HttpServletRequest request)
throws ConverterException
request - the JSON RequestConverterException - when the JSON content is not validpublic void setTarget(java.lang.Object target)
setTarget in class AbstractConverter<org.codehaus.groovy.grails.web.json.JSONWriter>target - the ObjectConverterprotected void handleCircularRelationship(java.lang.Object o)
throws ConverterException
ConverterExceptionpublic static ConverterConfiguration<JSON> getNamedConfig(java.lang.String configName) throws ConverterException
ConverterExceptionpublic static java.lang.Object use(java.lang.String configName,
groovy.lang.Closure<?> callable)
throws ConverterException
ConverterExceptionpublic static void use(java.lang.String cfgName)
throws ConverterException
ConverterExceptionpublic static void registerObjectMarshaller(java.lang.Class<?> clazz,
groovy.lang.Closure<?> callable)
throws ConverterException
ConverterExceptionpublic static void registerObjectMarshaller(java.lang.Class<?> clazz,
int priority,
groovy.lang.Closure<?> callable)
throws ConverterException
ConverterExceptionpublic static void registerObjectMarshaller(ObjectMarshaller<JSON> om) throws ConverterException
ConverterExceptionpublic static void registerObjectMarshaller(ObjectMarshaller<JSON> om, int priority) throws ConverterException
ConverterExceptionpublic static void createNamedConfig(java.lang.String name,
groovy.lang.Closure<?> callable)
throws ConverterException
ConverterExceptionpublic static void withDefaultConfiguration(groovy.lang.Closure<?> callable)
throws ConverterException
ConverterExceptionpublic void setIncludes(java.util.List<java.lang.String> includes)
setIncludes in interface org.codehaus.groovy.grails.web.converters.IncludeExcludeConverter<org.codehaus.groovy.grails.web.json.JSONWriter>public void setExcludes(java.util.List<java.lang.String> excludes)
setExcludes in interface org.codehaus.groovy.grails.web.converters.IncludeExcludeConverter<org.codehaus.groovy.grails.web.json.JSONWriter>