Package groovy.json
Class StreamingJsonBuilder.StreamingJsonDelegate
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.json.StreamingJsonBuilder.StreamingJsonDelegate
- All Implemented Interfaces:
- GroovyObject
- Enclosing class:
- StreamingJsonBuilder
The delegate used when invoking closures
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionStreamingJsonDelegate(Writer w, boolean first) StreamingJsonDelegate(Writer w, boolean first, JsonGenerator generator) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidcall(String name, JsonOutput.JsonUnescaped json) Writes an unescaped value.voidWrites the name and another JSON objectvoidWrites the given Writable as the value of the given attribute namevoidA collection and closure passed to a JSON builder will create a root JSON array applying the closure to each object in the collectionvoidWrites the name and value of a JSON attributevoidWrites the name and a JSON arrayvoidWrites the name and value of a JSON attributevoidcall(String name, Collection coll, Closure c) Delegates tocall(String, Iterable, Closure)voidWrites the name and a JSON arraystatic voidstatic voidcloneDelegateAndGetContent(Writer w, Closure c, boolean first) static voidcurryDelegateAndGetContent(Writer w, Closure c, Object o) static voidcurryDelegateAndGetContent(Writer w, Closure c, Object o, boolean first) invokeMethod(String name, Object args) Invokes the given method.static booleanisCollectionWithClosure(Object[] args) protected voidprotected voidwriteArray(List<Object> list) static ObjectwriteCollectionWithClosure(Writer writer, Collection coll, Closure closure) protected voidprotected voidwriteValue(Object value) Methods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClassMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface groovy.lang.GroovyObjectgetProperty, setProperty
- 
Field Details- 
writer
- 
firstprotected boolean first
- 
stateprotected groovy.json.StreamingJsonBuilder.StreamingJsonDelegate.State state
 
- 
- 
Constructor Details- 
StreamingJsonDelegate
- 
StreamingJsonDelegate
 
- 
- 
Method Details- 
getWriter- Returns:
- Obtains the current writer
 
- 
invokeMethodDescription copied from interface:GroovyObjectInvokes the given method.- Parameters:
- name- the name of the method to call
- args- the arguments to use for the method call
- Returns:
- the result of invoking the method
 
- 
callWrites the name and a JSON array- Parameters:
- name- The name of the JSON attribute
- list- The list representing the array
- Throws:
- IOException
 
- 
callWrites the name and a JSON array- Parameters:
- name- The name of the JSON attribute
- array- The list representing the array
- Throws:
- IOException
 
- 
callpublic void call(String name, Iterable coll, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure c) throws IOException A 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 collection
- c- a closure used to convert the objects of coll
- Throws:
- IOException
 
- 
callpublic void call(String name, Collection coll, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure c) throws IOException Delegates tocall(String, Iterable, Closure)- Throws:
- IOException
 
- 
callWrites the name and value of a JSON attribute- Parameters:
- name- The attribute name
- value- The value
- Throws:
- IOException
 
- 
callpublic void call(String name, Object value, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure callable) throws IOException Writes the name and value of a JSON attribute- Parameters:
- name- The attribute name
- value- The value
- Throws:
- IOException
 
- 
callpublic void call(String name, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure value) throws IOException Writes the name and another JSON object- Parameters:
- name- The attribute name
- value- The value
- Throws:
- IOException
 
- 
callWrites an unescaped value. Note: can cause invalid JSON if passed JSON is invalid- Parameters:
- name- The attribute name
- json- The value
- Throws:
- IOException
 
- 
callWrites the given Writable as the value of the given attribute name- Parameters:
- name- The attribute name
- json- The writable value
- Throws:
- IOException
 
- 
verifyValueprotected void verifyValue()
- 
writeName- Throws:
- IOException
 
- 
writeValue- Throws:
- IOException
 
- 
writeArray- Throws:
- IOException
 
- 
isCollectionWithClosure
- 
writeCollectionWithClosurepublic static Object writeCollectionWithClosure(Writer writer, Collection coll, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure closure) throws IOException - Throws:
- IOException
 
- 
cloneDelegateAndGetContentpublic static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure c) 
- 
cloneDelegateAndGetContentpublic static void cloneDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure c, boolean first) 
- 
curryDelegateAndGetContentpublic static void curryDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure c, Object o) 
- 
curryDelegateAndGetContentpublic static void curryDelegateAndGetContent(Writer w, @DelegatesTo(value=StreamingJsonDelegate.class,strategy=1) Closure c, Object o, boolean first) 
 
-