public static class StreamingJsonBuilder.StreamingJsonDelegate extends GroovyObjectSupport
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
first |
protected groovy.json.StreamingJsonBuilder.StreamingJsonDelegate.State |
state |
protected java.io.Writer |
writer |
| Constructor and Description |
|---|
StreamingJsonDelegate(java.io.Writer w,
boolean first) |
| Modifier and Type | Method and Description |
|---|---|
void |
call(java.lang.String name,
Closure value)
Writes the name and another JSON object
|
void |
call(java.lang.String name,
java.util.Collection coll,
Closure c)
Delegates to
call(String, Iterable, Closure) |
void |
call(java.lang.String name,
java.lang.Iterable 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(java.lang.String name,
JsonOutput.JsonUnescaped json)
Writes an unescaped value.
|
void |
call(java.lang.String name,
java.util.List<java.lang.Object> list)
Writes the name and a JSON array
|
void |
call(java.lang.String name,
java.lang.Object... array)
Writes the name and a JSON array
|
void |
call(java.lang.String name,
java.lang.Object value)
Writes the name and value of a JSON attribute
|
void |
call(java.lang.String name,
java.lang.Object value,
Closure callable)
Writes the name and value of a JSON attribute
|
void |
call(java.lang.String name,
Writable json)
Writes the given Writable as the value of the given attribute name
|
static void |
cloneDelegateAndGetContent(java.io.Writer w,
Closure c) |
static void |
cloneDelegateAndGetContent(java.io.Writer w,
Closure c,
boolean first) |
static void |
curryDelegateAndGetContent(java.io.Writer w,
Closure c,
java.lang.Object o) |
static void |
curryDelegateAndGetContent(java.io.Writer w,
Closure c,
java.lang.Object o,
boolean first) |
java.io.Writer |
getWriter() |
java.lang.Object |
invokeMethod(java.lang.String name,
java.lang.Object args)
Invokes the given method.
|
static boolean |
isCollectionWithClosure(java.lang.Object[] args) |
protected void |
verifyValue() |
protected void |
writeArray(java.util.List<java.lang.Object> list) |
static java.lang.Object |
writeCollectionWithClosure(java.io.Writer writer,
java.util.Collection coll,
Closure closure) |
static java.lang.Object |
writeCollectionWithClosure(java.io.Writer writer,
java.lang.Iterable coll,
Closure closure) |
protected void |
writeName(java.lang.String name) |
protected void |
writeValue(java.lang.Object value) |
getMetaClass, getProperty, setMetaClass, setPropertyprotected final java.io.Writer writer
protected boolean first
protected groovy.json.StreamingJsonBuilder.StreamingJsonDelegate.State state
public StreamingJsonDelegate(java.io.Writer w,
boolean first)
public java.io.Writer getWriter()
public java.lang.Object invokeMethod(java.lang.String name,
java.lang.Object args)
GroovyObjectinvokeMethod in interface GroovyObjectinvokeMethod in class GroovyObjectSupportname - the name of the method to callargs - the arguments to use for the method callpublic void call(java.lang.String name,
java.util.List<java.lang.Object> list)
throws java.io.IOException
name - The name of the JSON attributelist - The list representing the arrayjava.io.IOExceptionpublic void call(java.lang.String name,
java.lang.Object... array)
throws java.io.IOException
name - The name of the JSON attributearray - The list representing the arrayjava.io.IOExceptionpublic void call(java.lang.String name,
java.lang.Iterable coll,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure c)
throws java.io.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 colljava.io.IOExceptionpublic void call(java.lang.String name,
java.util.Collection coll,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure c)
throws java.io.IOException
call(String, Iterable, Closure)java.io.IOExceptionpublic void call(java.lang.String name,
java.lang.Object value)
throws java.io.IOException
name - The attribute namevalue - The valuejava.io.IOExceptionpublic void call(java.lang.String name,
java.lang.Object value,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure callable)
throws java.io.IOException
name - The attribute namevalue - The valuejava.io.IOExceptionpublic void call(java.lang.String name,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure value)
throws java.io.IOException
name - The attribute namevalue - The valuejava.io.IOExceptionpublic void call(java.lang.String name,
JsonOutput.JsonUnescaped json)
throws java.io.IOException
name - The attribute namejson - The valuejava.io.IOExceptionpublic void call(java.lang.String name,
Writable json)
throws java.io.IOException
name - The attribute namejson - The writable valuejava.io.IOExceptionprotected void verifyValue()
protected void writeName(java.lang.String name)
throws java.io.IOException
java.io.IOExceptionprotected void writeValue(java.lang.Object value)
throws java.io.IOException
java.io.IOExceptionprotected void writeArray(java.util.List<java.lang.Object> list)
throws java.io.IOException
java.io.IOExceptionpublic static boolean isCollectionWithClosure(java.lang.Object[] args)
public static java.lang.Object writeCollectionWithClosure(java.io.Writer writer,
java.util.Collection coll,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure closure)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.Object writeCollectionWithClosure(java.io.Writer writer,
java.lang.Iterable coll,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure closure)
throws java.io.IOException
java.io.IOExceptionpublic static void cloneDelegateAndGetContent(java.io.Writer w,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure c)
public static void cloneDelegateAndGetContent(java.io.Writer w,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure c,
boolean first)
public static void curryDelegateAndGetContent(java.io.Writer w,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure c,
java.lang.Object o)
public static void curryDelegateAndGetContent(java.io.Writer w,
@DelegatesTo(value=StreamingJsonBuilder.StreamingJsonDelegate.class)
Closure c,
java.lang.Object o,
boolean first)