|
||||||||||
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 grails.converters.JSON
public class JSON
A converter that converts domain classes, Maps, Lists, Arrays, POJOs and POGOs to JSON
Field Summary |
---|
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 |
array(Object o)
|
protected void |
bean(Object o)
Renders any Java object to the JSON Writer by leveraging the Java reflection API |
protected void |
domain(Object o)
Renders a instance of a Grails Domain Class to the JSON Writer |
protected Object |
extractIdValue(Object domainObject,
GrailsDomainClassProperty idProperty)
Reads the value of the primary identifier property of a domain class instance |
boolean |
isRenderDomainClassRelations()
Returns true if the JSON Converter is configured to convert referenced Domain Class instances as they are or just their id's (false) |
static Object |
parse(HttpServletRequest request)
Parses the given request's InputStream and returns ether a JSONObject or a JSONArry |
static Object |
parse(InputStream is,
String encoding)
Parses the given JSON and returns ether a JSONObject or a JSONArry |
static Object |
parse(String source)
Parses the given JSON String and returns ether a JSONObject or a JSONArry |
void |
render(HttpServletResponse response)
Directs the JSON Writer to the Outputstream of the HttpServletResponse and sets the Content-Type to text/json |
void |
render(Writer out)
Directs the JSON Writer to the given Writer |
JSON |
setRenderDomainClassRelations(boolean renderDomainClassRelations)
|
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 |
void |
value(Object o)
|
Methods inherited from class org.codehaus.groovy.grails.web.converters.AbstractConverter |
---|
createBeanWrapper, isJdk5Enum, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JSON()
public JSON(Object target)
target
- the Object to convertMethod Detail |
---|
public boolean isRenderDomainClassRelations()
public JSON setRenderDomainClassRelations(boolean renderDomainClassRelations)
renderDomainClassRelations
-
public void render(Writer out) throws ConverterException
render
in interface Converter
out
- the Writer
ConverterException
public void render(HttpServletResponse response) throws ConverterException
render
in interface Converter
response
- a HttpServletResponse
ConverterException
protected Object extractIdValue(Object domainObject, GrailsDomainClassProperty idProperty)
domainObject
- The domain class instanceidProperty
- The GrailsDomainClassProperty
protected void bean(Object o) throws ConverterException
o
- The Bean to render
ConverterException
protected void domain(Object o) throws ConverterException
o
- The Domain Class instance
ConverterException
public void array(Object o) throws ConverterException
o
- the array object
ConverterException
public void value(Object o) throws ConverterException
o
-
ConverterException
public String toString(boolean prettyPrint) throws JSONException
prettyPrint
- true, if the output should be indented, otherwise false
JSONException
public static Object parse(String source) throws ConverterException
source
- A string containing some JSON
ConverterException
- when the JSON content is not validpublic static Object 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
target
- the ObjectConverter
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |