Package groovy.json

Class 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

      Fields 
      Modifier and Type Field Description
      protected boolean first  
      protected groovy.json.StreamingJsonBuilder.StreamingJsonDelegate.State state  
      protected java.io.Writer writer  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void call​(java.lang.String name, JsonOutput.JsonUnescaped json)
      Writes an unescaped value.
      void call​(java.lang.String name, groovy.lang.Closure value)
      Writes the name and another JSON object
      void call​(java.lang.String name, groovy.lang.Writable json)
      Writes the given Writable as the value of the given attribute name
      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
      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... array)
      Writes the name and a JSON array
      void call​(java.lang.String name, java.lang.Object value, groovy.lang.Closure callable)
      Writes the name and value of a JSON attribute
      void call​(java.lang.String name, java.util.Collection coll, groovy.lang.Closure c)
      void call​(java.lang.String name, java.util.List<java.lang.Object> list)
      Writes the name and a JSON array
      static void cloneDelegateAndGetContent​(java.io.Writer w, groovy.lang.Closure c)  
      static void cloneDelegateAndGetContent​(java.io.Writer w, groovy.lang.Closure c, boolean first)  
      static void curryDelegateAndGetContent​(java.io.Writer w, groovy.lang.Closure c, java.lang.Object o)  
      static void curryDelegateAndGetContent​(java.io.Writer w, groovy.lang.Closure c, java.lang.Object o, boolean first)  
      java.io.Writer getWriter()  
      java.lang.Object invokeMethod​(java.lang.String name, java.lang.Object args)  
      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, groovy.lang.Closure closure)  
      protected void writeName​(java.lang.String name)  
      protected void writeValue​(java.lang.Object value)  
      • Methods inherited from class groovy.lang.GroovyObjectSupport

        getMetaClass, getProperty, setMetaClass, setProperty
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • writer

        protected final java.io.Writer writer
      • first

        protected boolean first
      • state

        protected groovy.json.StreamingJsonBuilder.StreamingJsonDelegate.State state
    • Constructor Detail

      • StreamingJsonDelegate

        public StreamingJsonDelegate​(java.io.Writer w,
                                     boolean first)
      • StreamingJsonDelegate

        public StreamingJsonDelegate​(java.io.Writer w,
                                     boolean first,
                                     JsonGenerator generator)
    • Method Detail

      • getWriter

        public java.io.Writer getWriter()
        Returns:
        Obtains the current writer
      • invokeMethod

        public java.lang.Object invokeMethod​(java.lang.String name,
                                             java.lang.Object args)
        Specified by:
        invokeMethod in interface groovy.lang.GroovyObject
        Overrides:
        invokeMethod in class groovy.lang.GroovyObjectSupport
      • call

        public void call​(java.lang.String name,
                         java.util.List<java.lang.Object> list)
                  throws java.io.IOException
        Writes the name and a JSON array
        Parameters:
        name - The name of the JSON attribute
        list - The list representing the array
        Throws:
        java.io.IOException
      • call

        public void call​(java.lang.String name,
                         java.lang.Object... array)
                  throws java.io.IOException
        Writes the name and a JSON array
        Parameters:
        name - The name of the JSON attribute
        array - The list representing the array
        Throws:
        java.io.IOException
      • call

        public void call​(java.lang.String name,
                         java.lang.Iterable coll,
                         @DelegatesTo(StreamingJsonDelegate.class)
                         groovy.lang.Closure c)
                  throws java.io.IOException
        A 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"}]}}'
         }
         
        Parameters:
        coll - a collection
        c - a closure used to convert the objects of coll
        Throws:
        java.io.IOException
      • call

        public void call​(java.lang.String name,
                         java.lang.Object value)
                  throws java.io.IOException
        Writes the name and value of a JSON attribute
        Parameters:
        name - The attribute name
        value - The value
        Throws:
        java.io.IOException
      • call

        public void call​(java.lang.String name,
                         java.lang.Object value,
                         @DelegatesTo(StreamingJsonDelegate.class)
                         groovy.lang.Closure callable)
                  throws java.io.IOException
        Writes the name and value of a JSON attribute
        Parameters:
        name - The attribute name
        value - The value
        Throws:
        java.io.IOException
      • call

        public void call​(java.lang.String name,
                         @DelegatesTo(StreamingJsonDelegate.class)
                         groovy.lang.Closure value)
                  throws java.io.IOException
        Writes the name and another JSON object
        Parameters:
        name - The attribute name
        value - The value
        Throws:
        java.io.IOException
      • call

        public void call​(java.lang.String name,
                         JsonOutput.JsonUnescaped json)
                  throws java.io.IOException
        Writes an unescaped value. Note: can cause invalid JSON if passed JSON is invalid
        Parameters:
        name - The attribute name
        json - The value
        Throws:
        java.io.IOException
      • call

        public void call​(java.lang.String name,
                         groovy.lang.Writable json)
                  throws java.io.IOException
        Writes the given Writable as the value of the given attribute name
        Parameters:
        name - The attribute name
        json - The writable value
        Throws:
        java.io.IOException
      • verifyValue

        protected void verifyValue()
      • writeName

        protected void writeName​(java.lang.String name)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writeValue

        protected void writeValue​(java.lang.Object value)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • writeArray

        protected void writeArray​(java.util.List<java.lang.Object> list)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • isCollectionWithClosure

        public static boolean isCollectionWithClosure​(java.lang.Object[] args)
      • writeCollectionWithClosure

        public static java.lang.Object writeCollectionWithClosure​(java.io.Writer writer,
                                                                  java.util.Collection coll,
                                                                  @DelegatesTo(StreamingJsonDelegate.class)
                                                                  groovy.lang.Closure closure)
                                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • cloneDelegateAndGetContent

        public static void cloneDelegateAndGetContent​(java.io.Writer w,
                                                      @DelegatesTo(StreamingJsonDelegate.class)
                                                      groovy.lang.Closure c)
      • cloneDelegateAndGetContent

        public static void cloneDelegateAndGetContent​(java.io.Writer w,
                                                      @DelegatesTo(StreamingJsonDelegate.class)
                                                      groovy.lang.Closure c,
                                                      boolean first)
      • curryDelegateAndGetContent

        public static void curryDelegateAndGetContent​(java.io.Writer w,
                                                      @DelegatesTo(StreamingJsonDelegate.class)
                                                      groovy.lang.Closure c,
                                                      java.lang.Object o)
      • curryDelegateAndGetContent

        public static void curryDelegateAndGetContent​(java.io.Writer w,
                                                      @DelegatesTo(StreamingJsonDelegate.class)
                                                      groovy.lang.Closure c,
                                                      java.lang.Object o,
                                                      boolean first)