public static class StreamingJsonBuilder.StreamingJsonDelegate extends groovy.lang.GroovyObjectSupport
The delegate used when invoking closures
Modifiers | Name | Description |
---|---|---|
private enum |
StreamingJsonBuilder.StreamingJsonDelegate.State |
Modifiers | Name | Description |
---|---|---|
protected boolean |
first |
|
private JsonGenerator |
generator |
|
protected StreamingJsonBuilder.StreamingJsonDelegate.State |
state |
|
protected java.io.Writer |
writer |
Constructor and description |
---|
StreamingJsonDelegate
(java.io.Writer w, boolean first) |
StreamingJsonDelegate
(java.io.Writer w, boolean first, JsonGenerator generator) |
Type Params | Return Type | Name and description |
---|---|---|
|
public void |
call(java.lang.String name, java.util.List<java.lang.Object> list) Writes the name and a JSON array |
|
public void |
call(java.lang.String name, java.lang.Object array) Writes the name and a JSON array |
|
public void |
call(java.lang.String name, java.lang.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 |
|
public void |
call(java.lang.String name, java.util.Collection coll, groovy.lang.Closure c) Delegates to call(String, Iterable, Closure) |
|
public void |
call(java.lang.String name, java.lang.Object value) Writes the name and value of a JSON attribute |
|
public void |
call(java.lang.String name, java.lang.Object value, groovy.lang.Closure callable) Writes the name and value of a JSON attribute |
|
public void |
call(java.lang.String name, groovy.lang.Closure value) Writes the name and another JSON object |
|
public void |
call(java.lang.String name, JsonUnescaped json) Writes an unescaped value. |
|
public void |
call(java.lang.String name, groovy.lang.Writable json) Writes an unescaped value. |
|
public static void |
cloneDelegateAndGetContent(java.io.Writer w, groovy.lang.Closure c) |
|
public static void |
cloneDelegateAndGetContent(java.io.Writer w, groovy.lang.Closure c, boolean first) |
|
private static void |
cloneDelegateAndGetContent(java.io.Writer w, groovy.lang.Closure c, boolean first, JsonGenerator generator) |
|
public static void |
curryDelegateAndGetContent(java.io.Writer w, groovy.lang.Closure c, java.lang.Object o) |
|
public static void |
curryDelegateAndGetContent(java.io.Writer w, groovy.lang.Closure c, java.lang.Object o, boolean first) |
|
private static void |
curryDelegateAndGetContent(java.io.Writer w, groovy.lang.Closure c, java.lang.Object o, boolean first, JsonGenerator generator) |
|
public java.io.Writer |
getWriter()
|
|
public java.lang.Object |
invokeMethod(java.lang.String name, java.lang.Object args) |
|
public static boolean |
isCollectionWithClosure(java.lang.Object[] args) |
|
public void |
setFirst(boolean first) |
|
protected void |
verifyValue() |
|
protected void |
writeArray(java.util.List<java.lang.Object> list) |
|
public static java.lang.Object |
writeCollectionWithClosure(java.io.Writer writer, java.util.Collection coll, groovy.lang.Closure closure) |
|
public static java.lang.Object |
writeCollectionWithClosure(java.io.Writer writer, java.lang.Iterable coll, groovy.lang.Closure closure, JsonGenerator generator) |
|
protected void |
writeName(java.lang.String name) |
|
private static void |
writeObject(java.io.Writer writer, java.lang.Object object, groovy.lang.Closure closure, JsonGenerator generator) |
|
private void |
writeObjects(java.lang.Iterable coll, groovy.lang.Closure c) |
|
protected void |
writeValue(java.lang.Object value) |
Methods inherited from class | Name |
---|---|
class groovy.lang.GroovyObjectSupport |
groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll(), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object) |
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"}]}}' }
name
- The name of the JSON attributecoll
- a collectionc
- a closure used to convert the objects of collDelegates to call(String, Iterable, Closure)
name
- The name of the JSON attributecoll
- 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 the name and value of a JSON attribute
name
- The attribute namevalue
- The valuecallable
- a closure used to convert the objects of collWrites the name and another JSON object
name
- The attribute namevalue
- The valueWrites an unescaped value. Note: can cause invalid JSON if passed JSON is invalid
name
- The attribute namejson
- The valueWrites an unescaped value. Note: can cause invalid JSON if passed JSON is invalid
name
- The attribute namejson
- The value