public static class StreamingJsonBuilder.StreamingJsonDelegate
extends groovy.lang.GroovyObjectSupport
Modifier and Type | Field and Description |
---|---|
protected boolean |
first |
protected groovy.json.StreamingJsonBuilder.StreamingJsonDelegate.State |
state |
protected Writer |
writer |
Constructor and Description |
---|
StreamingJsonDelegate(Writer w,
boolean first) |
Modifier and Type | Method and Description |
---|---|
void |
call(String name,
groovy.lang.Closure value)
Writes the name and another JSON object
|
void |
call(String name,
Collection coll,
groovy.lang.Closure c)
Delegates to
call(String, Iterable, Closure) |
void |
call(String name,
Iterable coll,
groovy.lang.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,
JsonOutput.JsonUnescaped json)
Writes an unescaped value.
|
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,
Object value)
Writes the name and value of a JSON attribute
|
void |
call(String name,
Object value,
groovy.lang.Closure callable)
Writes the name and value of a JSON attribute
|
void |
call(String name,
groovy.lang.Writable json)
Writes the given Writable as the value of the given attribute name
|
static void |
cloneDelegateAndGetContent(Writer w,
groovy.lang.Closure c) |
static void |
cloneDelegateAndGetContent(Writer w,
groovy.lang.Closure c,
boolean first) |
static void |
curryDelegateAndGetContent(Writer w,
groovy.lang.Closure c,
Object o) |
static void |
curryDelegateAndGetContent(Writer w,
groovy.lang.Closure c,
Object o,
boolean first) |
Writer |
getWriter() |
Object |
invokeMethod(String name,
Object args) |
static boolean |
isCollectionWithClosure(Object[] args) |
protected void |
verifyValue() |
protected void |
writeArray(List<Object> list) |
static Object |
writeCollectionWithClosure(Writer writer,
Collection coll,
groovy.lang.Closure closure) |
static Object |
writeCollectionWithClosure(Writer writer,
Iterable coll,
groovy.lang.Closure closure) |
protected void |
writeName(String name) |
protected void |
writeValue(Object value) |
protected final Writer writer
protected boolean first
protected groovy.json.StreamingJsonBuilder.StreamingJsonDelegate.State state
public StreamingJsonDelegate(Writer w, boolean first)
public Writer getWriter()
public Object invokeMethod(String name, Object args)
invokeMethod
in interface groovy.lang.GroovyObject
invokeMethod
in class groovy.lang.GroovyObjectSupport
public void call(String name, List<Object> list) throws IOException
name
- The name of the JSON attributelist
- The list representing the arrayIOException
public void call(String name, Object... array) throws IOException
name
- The name of the JSON attributearray
- The list representing the arrayIOException
public void call(String name, Iterable coll, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure c) throws IOException
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 collIOException
public void call(String name, Collection coll, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure c) throws IOException
call(String, Iterable, Closure)
IOException
public void call(String name, Object value) throws IOException
name
- The attribute namevalue
- The valueIOException
public void call(String name, Object value, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure callable) throws IOException
name
- The attribute namevalue
- The valueIOException
public void call(String name, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure value) throws IOException
name
- The attribute namevalue
- The valueIOException
public void call(String name, JsonOutput.JsonUnescaped json) throws IOException
name
- The attribute namejson
- The valueIOException
public void call(String name, groovy.lang.Writable json) throws IOException
name
- The attribute namejson
- The writable valueIOException
protected void verifyValue()
protected void writeName(String name) throws IOException
IOException
protected void writeValue(Object value) throws IOException
IOException
protected void writeArray(List<Object> list) throws IOException
IOException
public static boolean isCollectionWithClosure(Object[] args)
public static Object writeCollectionWithClosure(Writer writer, Collection coll, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure closure) throws IOException
IOException
public static Object writeCollectionWithClosure(Writer writer, Iterable coll, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure closure) throws IOException
IOException
public static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure c)
public static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure c, boolean first)
public static void curryDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure c, Object o)
public static void curryDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class) groovy.lang.Closure c, Object o, boolean first)