Class JsonGroovyBuilder

  • All Implemented Interfaces:
    groovy.lang.GroovyObject

    public class JsonGroovyBuilder
    extends groovy.lang.GroovyObjectSupport
    A Groovy builder for JSON values.
    def books1 = builder.books {
       book = [title: "The Definitive Guide to Grails", author: "Graeme Rocher"]
       book = [title: "The Definitive Guide to Grails", author: "Graeme Rocher"]
    }
    
    def books2 = builder.books {
       book = new Book(title: "The Definitive Guide to Grails",
                       author: "Graeme Rocher")
       book = new Book(title: "The Definitive Guide to Grails",
                       author: "Graeme Rocher")
    }
    
    def books3 = builder.books {
       book = {
          title = "The Definitive Guide to Grails"
          author= "Graeme Rocher"
       }
       book = {
          title = "The Definitive Guide to Grails"
          author= "Graeme Rocher"
       }
    }
    
    def books4 = builder.books {
       book {
          title = "The Definitive Guide to Grails"
          author= "Graeme Rocher"
       }
       book {
          title = "The Definitive Guide to Grails"
          author= "Graeme Rocher"
       }
    }
    
    def books5 = builder.books {
       2.times {
          book = {
             title = "The Definitive Guide to Grails"
             author= "Graeme Rocher"
          }
       }
    }
    
    def books6 = builder.books {
       2.times {
          book {
             title = "The Definitive Guide to Grails"
             author= "Graeme Rocher"
          }
       }
    }
    
    
     all 6 books variables output the same JSON
    
    {"books": {
       "book": [{
             "title": "The Definitive Guide to Grails",
             "author": "Graeme Rocher"
          },{
             "title": "The Definitive Guide to Grails",
             "author": "Graeme Rocher"
          }]
       }
    }
    
    Author:
    Andres Almiray
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      JsonConfig getJsonConfig()  
      java.lang.Object getProperty​(java.lang.String name)  
      java.lang.Object invokeMethod​(java.lang.String name, java.lang.Object arg)  
      void setJsonConfig​(JsonConfig jsonConfig)  
      void setProperty​(java.lang.String name, java.lang.Object value)  
      • Methods inherited from class groovy.lang.GroovyObjectSupport

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

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

      • JsonGroovyBuilder

        public JsonGroovyBuilder()
    • Method Detail

      • getJsonConfig

        public JsonConfig getJsonConfig()
      • setJsonConfig

        public void setJsonConfig​(JsonConfig jsonConfig)
      • getProperty

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

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

        public void setProperty​(java.lang.String name,
                                java.lang.Object value)
        Specified by:
        setProperty in interface groovy.lang.GroovyObject
        Overrides:
        setProperty in class groovy.lang.GroovyObjectSupport