Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## grails.converters
[Java] Class JSON

    java.lang.Object
      org.codehaus.groovy.grails.web.converters.AbstractConverter
          grails.converters.JSON

All Implemented Interfaces:
  IncludeExcludeConverter

    public class JSON
    extends AbstractConverter

A converter that converts domain classes, Maps, Lists, Arrays, POJOs and POGOs to JSON.

Authors:
  Siegfried Puchbauer
  Graeme Rocher

Nested Class Summary
`class` | `JSON.Builder`

Field Summary
`protected CircularReferenceBehaviour` | `circularReferenceBehaviour`
`protected ConverterConfiguration` | `config`
`protected boolean` | `prettyPrint`
`protected java.util.Stack` | `referenceStack`
`protected java.lang.Object` | `target`
`protected JSONWriter` | `writer`

Fields inherited from class AbstractConverter
contentType, encoding, excludes, includes

Constructor Summary
`JSON()` Default Constructor for a JSON Converter
`JSON(java.lang.Object target)` Creates a new JSON Converter for the given Object

Method Summary
`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` | `getNamedConfig(java.lang.String configName)`
`JSONWriter` | `getWriter()`
`protected void` | `handleCircularRelationship(java.lang.Object o)`
`protected ConverterConfiguration` | `initConfig()`
`ObjectMarshaller` | `lookupObjectMarshaller(java.lang.Object target)`
`static JSONElement` | `parse(java.io.Reader reader)` Parses the given JSON String and returns ether a JSONObject or a JSONArry
`static JSONElement` | `parse(java.lang.String source)` Parses the given JSON String and returns ether a JSONObject or a JSONArry
`static JSONElement` | `parse(java.io.InputStream is, java.lang.String encoding)` Parses the given JSON and returns ether a JSONObject or a JSONArry
`static java.lang.Object` | `parse(javax.servlet.http.HttpServletRequest request)` Parses the given request's InputStream and returns ether a JSONObject or a JSONArry
`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 om)`
`static void` | `registerObjectMarshaller(ObjectMarshaller om, int priority)`
`void` | `render(java.io.Writer out)` Directs the JSON Writer to the given Writer
`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` | `setExcludes(java.util.List excludes)`
`void` | `setIncludes(java.util.List 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 java.lang.Object` | `use(java.lang.String configName, groovy.lang.Closure callable)`
`static void` | `use(java.lang.String cfgName)`
`void` | `value(java.lang.Object o)` @param o
`static void` | `withDefaultConfiguration(groovy.lang.Closure callable)`

Methods inherited from class AbstractConverter
createBeanWrapper, getExcludes, getIncludes, setContentType, setEncoding, setExcludes, setIncludes, setTarget, toString

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Field Detail

### circularReferenceBehaviour

    protected final CircularReferenceBehaviour circularReferenceBehaviour

### config

    protected final ConverterConfiguration config

### prettyPrint

    protected boolean prettyPrint

### referenceStack

    protected java.util.Stack referenceStack

### target

    protected java.lang.Object target

### writer

    protected JSONWriter writer

Constructor Detail

### JSON

    public JSON()

  Default Constructor for a JSON Converter

### JSON

    public JSON(java.lang.Object target)

  Creates a new JSON Converter for the given Object
  Parameters:
    `target` - the Object to convert

Method Detail

### build

    public void build(@java.lang.SuppressWarnings("rawtypes") groovy.lang.Closure c)

### convertAnother

    public void convertAnother(java.lang.Object o)

### createNamedConfig

    public static void createNamedConfig(java.lang.String name, groovy.lang.Closure callable)

### getDepth

    public int getDepth()

### getNamedConfig

    public static ConverterConfiguration getNamedConfig(java.lang.String configName)

### getWriter

    public JSONWriter getWriter()

### handleCircularRelationship

    protected void handleCircularRelationship(java.lang.Object o)

### initConfig

    protected ConverterConfiguration initConfig()

### lookupObjectMarshaller

    public ObjectMarshaller lookupObjectMarshaller(java.lang.Object target)

### parse

    public static JSONElement parse(java.io.Reader reader)

  Parses the given JSON String and returns ether a JSONObject or a JSONArry
  throws:
    ConverterException when the JSON content is not valid
  Parameters:
    `reader` - JSON source
  Returns:
    ether a JSONObject or a JSONArray - depending on the given JSON

### parse

    public static JSONElement parse(java.lang.String source)

  Parses the given JSON String and returns ether a JSONObject or a JSONArry
  throws:
    ConverterException when the JSON content is not valid
  Parameters:
    `source` - A string containing some JSON
  Returns:
    ether a JSONObject or a JSONArray - depending on the given JSON

### parse

    public static JSONElement parse(java.io.InputStream is, java.lang.String encoding)

  Parses the given JSON and returns ether a JSONObject or a JSONArry
  throws:
    ConverterException when the JSON content is not valid
  Parameters:
    `is` - An InputStream which delivers some JSON
    `encoding` - the Character Encoding to use
  Returns:
    ether a JSONObject or a JSONArray - depending on the given JSON

### parse

    public static java.lang.Object parse(javax.servlet.http.HttpServletRequest request)

  Parses the given request's InputStream and returns ether a JSONObject or a JSONArry
  throws:
    ConverterException when the JSON content is not valid
  Parameters:
    `request` - the JSON Request
  Returns:
    ether a JSONObject or a JSONArray - depending on the given JSON

### property

    public void property(java.lang.String key, java.lang.Object value)

### registerObjectMarshaller

    public static void registerObjectMarshaller(java.lang.Class clazz, groovy.lang.Closure callable)

### registerObjectMarshaller

    public static void registerObjectMarshaller(java.lang.Class clazz, int priority, groovy.lang.Closure callable)

### registerObjectMarshaller

    public static void registerObjectMarshaller(ObjectMarshaller om)

### registerObjectMarshaller

    public static void registerObjectMarshaller(ObjectMarshaller om, int priority)

### render

    public void render(java.io.Writer out)

  Directs the JSON Writer to the given Writer
  throws:
    org.codehaus.groovy.grails.web.converters.exceptions.ConverterException
  Parameters:
    `out` - the Writer

### render

    public 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
  throws:
    ConverterException
  Parameters:
    `response` - a HttpServletResponse

### setExcludes

    @java.lang.Override}
    public void setExcludes(java.util.List excludes)

### setIncludes

    @java.lang.Override
    public void setIncludes(java.util.List includes)

### setPrettyPrint

    public void setPrettyPrint(boolean prettyPrint)

### setTarget

    @java.lang.Override}
    public void setTarget(java.lang.Object target)

  Sets the Object which is later converted to JSON
  Parameters:
    `target` - the Object
  See Also:
    Converter

### toString

    public java.lang.String toString(boolean prettyPrint)

  Performs the conversion and returns the resulting JSON as String
  throws:
    JSONException
  Parameters:
    `prettyPrint` - true, if the output should be indented, otherwise false
  Returns:
    a JSON String

### use

    public static java.lang.Object use(java.lang.String configName, groovy.lang.Closure callable)

### use

    public static void use(java.lang.String cfgName)

### value

    public void value(java.lang.Object o)

  throws:
    ConverterException
  Parameters:
    o

### withDefaultConfiguration

    public static void withDefaultConfiguration(groovy.lang.Closure callable)

Groovy Documentation