|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.codehaus.groovy.grails.web.converters.AbstractConverter<JSONWriter> grails.converters.JSON
public class JSON
A converter that converts domain classes, Maps, Lists, Arrays, POJOs and POGOs to JSON
Nested Class Summary | |
---|---|
class |
JSON.Builder
|
Nested classes/interfaces inherited from interface org.codehaus.groovy.grails.web.converters.Converter |
---|
Converter.CircularReferenceBehaviour |
Field Summary | |
---|---|
protected Stack<Object> |
referenceStack
|
protected JSONWriter |
writer
|
Fields inherited from interface org.codehaus.groovy.grails.web.converters.Converter |
---|
DEFAULT_REQUEST_ENCODING |
Constructor Summary | |
---|---|
JSON()
Default Constructor for a JSON Converter |
|
JSON(Object target)
Creates a new JSON Converter for the given Object |
Method Summary | |
---|---|
void |
build(groovy.lang.Closure c)
|
void |
convertAnother(Object o)
|
static void |
createNamedConfig(String name,
groovy.lang.Closure callable)
|
int |
getDepth()
|
static ConverterConfiguration<JSON> |
getNamedConfig(String configName)
|
JSONWriter |
getWriter()
|
protected void |
handleCircularRelationship(Object o)
|
protected ConverterConfiguration<JSON> |
initConfig()
|
ObjectMarshaller<JSON> |
lookupObjectMarshaller(Object target)
|
static Object |
parse(HttpServletRequest request)
Parses the given request's InputStream and returns ether a JSONObject or a JSONArry |
static JSONElement |
parse(InputStream is,
String encoding)
Parses the given JSON and returns ether a JSONObject or a JSONArry |
static JSONElement |
parse(Reader reader)
Parses the given JSON String and returns ether a JSONObject or a JSONArry |
static JSONElement |
parse(String source)
Parses the given JSON String and returns ether a JSONObject or a JSONArry |
void |
property(String key,
Object value)
|
static void |
registerObjectMarshaller(Class clazz,
groovy.lang.Closure callable)
|
static void |
registerObjectMarshaller(Class clazz,
int priority,
groovy.lang.Closure callable)
|
static void |
registerObjectMarshaller(ObjectMarshaller<JSON> om)
|
static void |
registerObjectMarshaller(ObjectMarshaller<JSON> om,
int priority)
|
void |
render(HttpServletResponse response)
Directs the JSON Writer to the Outputstream of the HttpServletResponse and sets the Content-Type to application/json |
void |
render(Writer out)
Directs the JSON Writer to the given Writer |
void |
setPrettyPrint(boolean prettyPrint)
|
void |
setTarget(Object target)
Sets the Object which is later converted to JSON |
String |
toString(boolean prettyPrint)
Performs the conversion and returns the resulting JSON as String |
static void |
use(String cfgName)
|
static Object |
use(String configName,
groovy.lang.Closure callable)
|
void |
value(Object o)
|
static void |
withDefaultConfiguration(groovy.lang.Closure callable)
|
Methods inherited from class org.codehaus.groovy.grails.web.converters.AbstractConverter |
---|
createBeanWrapper, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected JSONWriter writer
protected Stack<Object> referenceStack
Constructor Detail |
---|
public JSON()
public JSON(Object target)
target
- the Object to convertMethod Detail |
---|
protected ConverterConfiguration<JSON> initConfig()
public void setPrettyPrint(boolean prettyPrint)
public void render(Writer out) throws ConverterException
render
in interface Converter<JSONWriter>
out
- the Writer
ConverterException
public void render(HttpServletResponse response) throws ConverterException
render
in interface Converter<JSONWriter>
response
- a HttpServletResponse
ConverterException
public JSONWriter getWriter() throws ConverterException
getWriter
in interface Converter<JSONWriter>
ConverterException
public void convertAnother(Object o) throws ConverterException
convertAnother
in interface Converter<JSONWriter>
ConverterException
public void build(groovy.lang.Closure c) throws ConverterException
build
in interface Converter<JSONWriter>
ConverterException
public void value(Object o) throws ConverterException
o
-
ConverterException
public ObjectMarshaller<JSON> lookupObjectMarshaller(Object target)
lookupObjectMarshaller
in interface Converter<JSONWriter>
public int getDepth()
public void property(String key, Object value) throws JSONException, ConverterException
JSONException
ConverterException
public String toString(boolean prettyPrint) throws JSONException
prettyPrint
- true, if the output should be indented, otherwise false
JSONException
public static JSONElement parse(Reader reader) throws ConverterException
reader
- JSON source
ConverterException
- when the JSON content is not validpublic static JSONElement parse(String source) throws ConverterException
source
- A string containing some JSON
ConverterException
- when the JSON content is not validpublic static JSONElement parse(InputStream is, String encoding) throws ConverterException
is
- An InputStream which delivers some JSONencoding
- the Character Encoding to use
ConverterException
- when the JSON content is not validpublic static Object parse(HttpServletRequest request) throws ConverterException
request
- the JSON Request
ConverterException
- when the JSON content is not validpublic void setTarget(Object target)
setTarget
in class AbstractConverter<JSONWriter>
target
- the ObjectConverter
protected void handleCircularRelationship(Object o) throws ConverterException
ConverterException
public static ConverterConfiguration<JSON> getNamedConfig(String configName) throws ConverterException
ConverterException
public static Object use(String configName, groovy.lang.Closure callable) throws ConverterException
ConverterException
public static void use(String cfgName) throws ConverterException
ConverterException
public static void registerObjectMarshaller(Class clazz, groovy.lang.Closure callable) throws ConverterException
ConverterException
public static void registerObjectMarshaller(Class clazz, int priority, groovy.lang.Closure callable) throws ConverterException
ConverterException
public static void registerObjectMarshaller(ObjectMarshaller<JSON> om) throws ConverterException
ConverterException
public static void registerObjectMarshaller(ObjectMarshaller<JSON> om, int priority) throws ConverterException
ConverterException
public static void createNamedConfig(String name, groovy.lang.Closure callable) throws ConverterException
ConverterException
public static void withDefaultConfiguration(groovy.lang.Closure callable) throws ConverterException
ConverterException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |