public static class StreamingJsonBuilder.StreamingJsonDelegate
extends GroovyObjectSupport
The delegate used when invoking closures
| Modifiers | Name | Description |
|---|---|---|
protected boolean |
first |
Indicates whether the next entry is the first one in the current context. |
protected StreamingJsonBuilder.StreamingJsonDelegate.State |
state |
Tracks whether the next token should be a JSON name or value. |
protected Writer |
writer |
Writer receiving the streamed JSON output. |
| Constructor and description |
|---|
StreamingJsonDelegate(Writer w, boolean first)Creates a delegate backed by the default generator. |
StreamingJsonDelegate(Writer w, boolean first, JsonGenerator generator)Creates a delegate backed by the supplied generator. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
call(String name, List<Object> list)Writes the name and a JSON array |
|
public void |
call(String name, Object array)Writes the name and a JSON array |
|
public void |
call(String name, 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 |
|
public void |
call(String name, Collection coll, Closure c)Delegates to call(String, Iterable, Closure) |
|
public void |
call(String name, Object value)Writes the name and value of a JSON attribute |
|
public void |
call(String name, Object value, Closure callable)Writes the name and value of a JSON attribute |
|
public void |
call(String name, Closure value)Writes the name and another JSON object |
|
public void |
call(String name, JsonUnescaped json)Writes an unescaped value. |
|
public void |
call(String name, Writable json)Writes the given Writable as the value of the given attribute name |
|
public static void |
cloneDelegateAndGetContent(Writer w, Closure c)Clones a closure, assigns this delegate model, and writes its JSON content. |
|
public static void |
cloneDelegateAndGetContent(Writer w, Closure c, boolean first)Clones a closure, assigns this delegate model, and writes its JSON content. |
|
public static void |
curryDelegateAndGetContent(Writer w, Closure c, Object o)Curries an object into a closure, assigns this delegate model, and writes its JSON content. |
|
public static void |
curryDelegateAndGetContent(Writer w, Closure c, Object o, boolean first)Curries an object into a closure, assigns this delegate model, and writes its JSON content. |
|
public Writer |
getWriter()
|
|
public Object |
invokeMethod(String name, Object args)Handles builder-style method calls for nested JSON output. |
|
public static boolean |
isCollectionWithClosure(Object[] args)Indicates whether the supplied arguments represent a collection and closure pair. |
|
protected void |
verifyValue()Verifies that the current output state expects a JSON value next. |
|
protected void |
writeArray(List<Object> list)Writes a JSON array value. |
|
public static Object |
writeCollectionWithClosure(Writer writer, Collection coll, Closure closure)Writes a JSON array by applying a closure to each element in the collection. |
|
protected void |
writeName(String name)Writes a JSON name and the following colon separator. |
|
protected void |
writeValue(Object value)Writes a scalar JSON value. |
| Methods inherited from class | Name |
|---|---|
class GroovyObjectSupport |
getMetaClass, setMetaClass |
Indicates whether the next entry is the first one in the current context.
Tracks whether the next token should be a JSON name or value.
Writer receiving the streamed JSON output.
Creates a delegate backed by the default generator.
w - the writer receiving JSON outputfirst - whether the next entry is the first entryCreates a delegate backed by the supplied generator.
w - the writer receiving JSON outputfirst - whether the next entry is the first entrygenerator - the generator used to serialize scalar valuesWrites 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 collDelegates to call(String, Iterable, Closure)
Writes 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 valueWrites 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 the given Writable as the value of the given attribute name
name - The attribute namejson - The writable valueClones a closure, assigns this delegate model, and writes its JSON content.
w - the destination writerc - the closure describing the JSON objectClones a closure, assigns this delegate model, and writes its JSON content.
w - the destination writerc - the closure describing the JSON objectfirst - whether the next entry is the first entryCurries an object into a closure, assigns this delegate model, and writes its JSON content.
w - the destination writerc - the closure describing the JSON objecto - the object to curry into the closureCurries an object into a closure, assigns this delegate model, and writes its JSON content.
w - the destination writerc - the closure describing the JSON objecto - the object to curry into the closurefirst - whether the next entry is the first entry
Handles builder-style method calls for nested JSON output.
name - the JSON name being writtenargs - the value, values, or closure associated with the nameIndicates whether the supplied arguments represent a collection and closure pair.
args - the arguments to inspecttrue if the arguments are a collection plus closure pairVerifies that the current output state expects a JSON value next.
Writes a JSON array value.
list - the list to serializeWrites a JSON array by applying a closure to each element in the collection.
writer - the destination writercoll - the collection to serializeclosure - the closure used to build each JSON object entryWrites a JSON name and the following colon separator.
name - the JSON name to writeWrites a scalar JSON value.
value - the value to writeCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.