Class JsonGroovyBuilder

java.lang.Object
groovy.lang.GroovyObjectSupport
net.sf.json.groovy.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"
 }]
 }
 }
 
  • Field Details

  • Constructor Details

    • JsonGroovyBuilder

      public JsonGroovyBuilder()
  • Method Details

    • getJsonConfig

      public JsonConfig getJsonConfig()
    • setJsonConfig

      public void setJsonConfig(JsonConfig jsonConfig)
    • getProperty

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

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

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

      private Object _getProperty(String name)
    • append

      private void append(String key, Object value)
    • _append

      private void _append(String key, Object value, JSON target)
    • createArray

      private JSON createArray(List list)
    • createObject

      private JSON createObject(groovy.lang.Closure closure)
    • createObject

      private JSON createObject(Map map)
    • createObject

      private JSON createObject(String name, Object arg)