The delegate used when invoking closures
Constructor and description |
---|
StreamingJsonBuilder.StreamingJsonDelegate
(Writer w, boolean first) |
Type | Name and description |
---|---|
void |
call(String name, List<Object> list) Writes the name and a JSON array |
void |
call(String name, Object... array) Writes the name and a JSON array |
void |
call(String name, Collection coll, Closure c) A collection and closure passed to a JSON builder will create a root JSON array applying the closure to each object in the collection |
void |
call(String name, Object value) Writes the name and value of a JSON attribute |
void |
call(String name, JsonUnescaped json) Writes an unescaped value. |
static void |
cloneDelegateAndGetContent(Writer w, Closure c) |
static void |
cloneDelegateAndGetContent(Writer w, Closure c, boolean first) |
static void |
curryDelegateAndGetContent(Writer w, Closure c, Object o) |
static void |
curryDelegateAndGetContent(Writer w, Closure c, Object o, boolean first) |
Object |
invokeMethod(String name, Object args) |
static boolean |
isCollectionWithClosure(Object[] args) |
static Object |
writeCollectionWithClosure(Writer writer, Collection coll, Closure closure) |
Methods inherited from class | Name |
---|---|
class GroovyObjectSupport |
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty |
class Object |
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Writes the name and a JSON array
name
- The name of the JSON attributelist
- The list representing the arrayWrites the name and a JSON array
name
- The name of the JSON attributearray
- The list representing the arrayA collection and closure passed to a JSON builder will create a root JSON array applying the closure to each object in the collection
Example:
class Author { String name } def authorList = [new Author (name: "Guillaume"), new Author (name: "Jochen"), new Author (name: "Paul")] new StringWriter().with { w -> def json = new groovy.json.StreamingJsonBuilder(w) json.book { authors authorList, { Author author -> name author.name } } assert w.toString() == '{"book":{"authors":[{"name":"Guillaume"},{"name":"Jochen"},{"name":"Paul"}]}}' }
coll
- a collectionc
- a closure used to convert the objects of collWrites the name and value of a JSON attribute
name
- The attribute namevalue
- The valueWrites an unescaped value. Note: can cause invalid JSON if passed JSON is invalid
name
- The attribute namejson
- The valueCopyright © 2003-2015 The Apache Software Foundation. All rights reserved.