public class JSON extends AbstractConverter implements IncludeExcludeConverter
A converter that converts domain classes, Maps, Lists, Arrays, POJOs and POGOs to JSON.
Modifiers | Name | Description |
---|---|---|
class |
JSON.Builder |
|
private enum |
JSON.BuilderMode |
Modifiers | Name | Description |
---|---|---|
private static java.lang.String |
CACHED_JSON |
|
protected CircularReferenceBehaviour |
circularReferenceBehaviour |
|
protected ConverterConfiguration<JSON> |
config |
|
private static org.apache.commons.logging.Log |
log |
|
protected boolean |
prettyPrint |
|
protected java.util.Stack<java.lang.Object> |
referenceStack |
|
protected java.lang.Object |
target |
|
protected JSONWriter |
writer |
Fields inherited from class | Fields |
---|---|
class AbstractConverter |
contentType, encoding, excludes, includes |
Type Params | Return Type | Name and description |
---|---|---|
|
public void |
build(groovy.lang.Closure c) |
|
public void |
convertAnother(java.lang.Object o) |
|
public static void |
createNamedConfig(java.lang.String name, groovy.lang.Closure<?> callable) |
|
private void |
finalizeRender(java.io.Writer out) |
|
public int |
getDepth() |
|
public static ConverterConfiguration<JSON> |
getNamedConfig(java.lang.String configName) |
|
public JSONWriter |
getWriter() |
|
protected void |
handleCircularRelationship(java.lang.Object o) |
|
protected ConverterConfiguration<JSON> |
initConfig() |
|
public ObjectMarshaller<JSON> |
lookupObjectMarshaller(java.lang.Object target) |
|
public static JSONElement |
parse(java.io.Reader reader) Parses the given JSON String and returns either a JSONObject or a JSONArray |
|
public static JSONElement |
parse(java.lang.String source) Parses the given JSON String and returns either a JSONObject or a JSONArray |
|
public static JSONElement |
parse(java.io.InputStream is, java.lang.String encoding) Parses the given JSON and returns either a JSONObject or a JSONArray |
|
public static java.lang.Object |
parse(jakarta.servlet.http.HttpServletRequest request) Parses the given request's InputStream and returns either a JSONObject or a JSONArray |
|
private void |
prepareRender(java.io.Writer out) |
|
public void |
property(java.lang.String key, java.lang.Object value) |
|
public static void |
registerObjectMarshaller(java.lang.Class<?> clazz, groovy.lang.Closure<?> callable) |
|
public static void |
registerObjectMarshaller(java.lang.Class<?> clazz, int priority, groovy.lang.Closure<?> callable) |
|
public static void |
registerObjectMarshaller(ObjectMarshaller<JSON> om) |
|
public static void |
registerObjectMarshaller(ObjectMarshaller<JSON> om, int priority) |
|
public void |
render(java.io.Writer out) Directs the JSON Writer to the given Writer |
|
public void |
render(jakarta.servlet.http.HttpServletResponse response) Directs the JSON Writer to the Outputstream of the HttpServletResponse and sets the Content-Type to application/json |
|
public void |
setExcludes(java.util.List<java.lang.String> excludes) |
|
public void |
setIncludes(java.util.List<java.lang.String> includes) |
|
public void |
setPrettyPrint(boolean prettyPrint) |
|
public void |
setTarget(java.lang.Object target) Sets the Object which is later converted to JSON |
|
public java.lang.String |
toString(boolean prettyPrint) Performs the conversion and returns the resulting JSON as String |
|
public static java.lang.Object |
use(java.lang.String configName, groovy.lang.Closure<?> callable) |
|
public static void |
use(java.lang.String cfgName) |
|
public void |
value(java.lang.Object o)
|
|
public static void |
withDefaultConfiguration(groovy.lang.Closure<?> callable) |
Methods inherited from class | Name |
---|---|
class AbstractConverter |
createBeanWrapper, getExcludes, getIncludes, setContentType, setEncoding, setExcludes, setIncludes, setTarget, toString, writeTo |
Default Constructor for a JSON Converter
Creates a new JSON Converter for the given Object
target
- the Object to convertParses the given JSON String and returns either a JSONObject or a JSONArray
reader
- JSON sourceParses the given JSON String and returns either a JSONObject or a JSONArray
source
- A string containing some JSONParses the given JSON and returns either a JSONObject or a JSONArray
is
- An InputStream which delivers some JSONencoding
- the Character Encoding to useParses the given request's InputStream and returns either a JSONObject or a JSONArray
request
- the JSON RequestDirects the JSON Writer to the given Writer
out
- the WriterDirects the JSON Writer to the Outputstream of the HttpServletResponse and sets the Content-Type to application/json
response
- a HttpServletResponseSets the Object which is later converted to JSON
target
- the ObjectPerforms the conversion and returns the resulting JSON as String
prettyPrint
- true, if the output should be indented, otherwise false