grails.converters
Class JSON

java.lang.Object
  extended by org.codehaus.groovy.grails.web.converters.AbstractConverter
      extended by grails.converters.JSON
All Implemented Interfaces:
Converter

public class JSON
extends AbstractConverter
implements Converter

Author:
Siegfried Puchbauer

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)
           
 Object asType(Class type)
           
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
 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)
 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)
           
 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
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSON

public JSON()
Default Constructor for a JSON Converter


JSON

public JSON(Object target)
Creates a new JSON Converter for the given Object

Parameters:
target - the Object to convert
Method Detail

isRenderDomainClassRelations

public 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)

Returns:
true or false ;-)

setRenderDomainClassRelations

public JSON setRenderDomainClassRelations(boolean renderDomainClassRelations)
Parameters:
renderDomainClassRelations -
Returns:
the JSON instance for chaining

render

public void render(Writer out)
            throws ConverterException
Directs the JSON Writer to the given Writer

Specified by:
render in interface Converter
Parameters:
out - the Writer
Throws:
ConverterException

render

public void render(HttpServletResponse response)
            throws ConverterException
Directs the JSON Writer to the Outputstream of the HttpServletResponse and sets the Content-Type to text/json

Specified by:
render in interface Converter
Parameters:
response - a HttpServletResponse
Throws:
ConverterException

bean

protected void bean(Object o)
             throws ConverterException
Renders any Java object to the JSON Writer by leveraging the Java reflection API

Parameters:
o - The Bean to render
Throws:
ConverterException

domain

protected void domain(Object o)
               throws ConverterException
Renders a instance of a Grails Domain Class to the JSON Writer

Parameters:
o - The Domain Class instance
Throws:
ConverterException

array

public void array(Object o)
           throws ConverterException
Parameters:
o - the array object
Throws:
ConverterException

value

public void value(Object o)
           throws ConverterException
Parameters:
o -
Throws:
ConverterException

toString

public String toString(boolean prettyPrint)
                throws JSONException
Performs the conversion and returns the resulting JSON as String

Parameters:
prettyPrint - true, if the output should be indented, otherwise false
Returns:
a JSON String
Throws:
JSONException

setTarget

public void setTarget(Object target)
Specified by:
setTarget in class AbstractConverter
Parameters:
target -

asType

public Object asType(Class type)
Parameters:
type -
Returns:


Copyright (c) 2005-2006 The Grails project