Package groovy.json
Class StreamingJsonBuilder.StreamingJsonDelegate
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.json.StreamingJsonBuilder.StreamingJsonDelegate
- All Implemented Interfaces:
groovy.lang.GroovyObject
- Enclosing class:
- StreamingJsonBuilder
public static class StreamingJsonBuilder.StreamingJsonDelegate
extends groovy.lang.GroovyObjectSupport
The delegate used when invoking closures
-
Field Summary
-
Constructor Summary
Constructors Constructor Description StreamingJsonDelegate(Writer w, boolean first)StreamingJsonDelegate(Writer w, boolean first, JsonGenerator generator) -
Method Summary
Modifier and Type Method Description voidcall(String name, JsonOutput.JsonUnescaped json)Writes an unescaped value.voidcall(String name, groovy.lang.Closure value)Writes the name and another JSON objectvoidcall(String name, groovy.lang.Writable json)Writes the given Writable as the value of the given attribute namevoidcall(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 collectionvoidcall(String name, Object value)Writes the name and value of a JSON attributevoidcall(String name, Object... array)Writes the name and a JSON arrayvoidcall(String name, Object value, groovy.lang.Closure callable)Writes the name and value of a JSON attributevoidcall(String name, Collection coll, groovy.lang.Closure c)Delegates tocall(String, Iterable, Closure)voidcall(String name, List<Object> list)Writes the name and a JSON arraystatic voidcloneDelegateAndGetContent(Writer w, groovy.lang.Closure c)static voidcloneDelegateAndGetContent(Writer w, groovy.lang.Closure c, boolean first)static voidcurryDelegateAndGetContent(Writer w, groovy.lang.Closure c, Object o)static voidcurryDelegateAndGetContent(Writer w, groovy.lang.Closure c, Object o, boolean first)WritergetWriter()ObjectinvokeMethod(String name, Object args)static booleanisCollectionWithClosure(Object[] args)protected voidverifyValue()protected voidwriteArray(List<Object> list)static ObjectwriteCollectionWithClosure(Writer writer, Collection coll, groovy.lang.Closure closure)protected voidwriteName(String name)protected voidwriteValue(Object value)Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClassMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface groovy.lang.GroovyObject
getProperty, setProperty
-
Field Details
-
writer
-
first
protected boolean first -
state
protected groovy.json.StreamingJsonBuilder.StreamingJsonDelegate.State state
-
-
Constructor Details
-
StreamingJsonDelegate
-
StreamingJsonDelegate
-
-
Method Details
-
getWriter
- Returns:
- Obtains the current writer
-
invokeMethod
-
call
Writes the name and a JSON array- Parameters:
name- The name of the JSON attributelist- The list representing the array- Throws:
IOException
-
call
Writes the name and a JSON array- Parameters:
name- The name of the JSON attributearray- The list representing the array- Throws:
IOException
-
call
public void call(String name, Iterable coll, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure c) throws IOExceptionA collection and closure passed to a JSON builder will create a root JSON array applying the closure to each object in the collectionExample:
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"}]}}' }- Parameters:
coll- a collectionc- a closure used to convert the objects of coll- Throws:
IOException
-
call
public void call(String name, Collection coll, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure c) throws IOExceptionDelegates tocall(String, Iterable, Closure)- Throws:
IOException
-
call
Writes the name and value of a JSON attribute- Parameters:
name- The attribute namevalue- The value- Throws:
IOException
-
call
public void call(String name, Object value, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure callable) throws IOExceptionWrites the name and value of a JSON attribute- Parameters:
name- The attribute namevalue- The value- Throws:
IOException
-
call
public void call(String name, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure value) throws IOExceptionWrites the name and another JSON object- Parameters:
name- The attribute namevalue- The value- Throws:
IOException
-
call
Writes an unescaped value. Note: can cause invalid JSON if passed JSON is invalid- Parameters:
name- The attribute namejson- The value- Throws:
IOException
-
call
Writes the given Writable as the value of the given attribute name- Parameters:
name- The attribute namejson- The writable value- Throws:
IOException
-
verifyValue
protected void verifyValue() -
writeName
- Throws:
IOException
-
writeValue
- Throws:
IOException
-
writeArray
- Throws:
IOException
-
isCollectionWithClosure
-
writeCollectionWithClosure
public static Object writeCollectionWithClosure(Writer writer, Collection coll, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure closure) throws IOException- Throws:
IOException
-
cloneDelegateAndGetContent
public static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure c) -
cloneDelegateAndGetContent
public static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure c, boolean first) -
curryDelegateAndGetContent
public static void curryDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure c, Object o) -
curryDelegateAndGetContent
public static void curryDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) groovy.lang.Closure c, Object o, boolean first)
-