Package net.sf.json.groovy
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.GroovyObjectSupportA 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 Summary
Fields Modifier and Type Field Description private JSONcurrentprivate static java.lang.StringJSONprivate JsonConfigjsonConfigprivate java.util.Mappropertiesprivate java.util.Stackstack
-
Constructor Summary
Constructors Constructor Description JsonGroovyBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void_append(java.lang.String key, java.lang.Object value, JSON target)private java.lang.Object_getProperty(java.lang.String name)private voidappend(java.lang.String key, java.lang.Object value)private JSONcreateArray(java.util.List list)private JSONcreateObject(groovy.lang.Closure closure)private JSONcreateObject(java.lang.String name, java.lang.Object arg)private JSONcreateObject(java.util.Map map)JsonConfiggetJsonConfig()java.lang.ObjectgetProperty(java.lang.String name)java.lang.ObjectinvokeMethod(java.lang.String name, java.lang.Object arg)voidsetJsonConfig(JsonConfig jsonConfig)voidsetProperty(java.lang.String name, java.lang.Object value)
-
-
-
Field Detail
-
JSON
private static final java.lang.String JSON
- See Also:
- Constant Field Values
-
current
private JSON current
-
properties
private java.util.Map properties
-
stack
private java.util.Stack stack
-
jsonConfig
private JsonConfig jsonConfig
-
-
Method Detail
-
getJsonConfig
public JsonConfig getJsonConfig()
-
setJsonConfig
public void setJsonConfig(JsonConfig jsonConfig)
-
getProperty
public java.lang.Object getProperty(java.lang.String name)
- Specified by:
getPropertyin interfacegroovy.lang.GroovyObject- Overrides:
getPropertyin classgroovy.lang.GroovyObjectSupport
-
invokeMethod
public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object arg)- Specified by:
invokeMethodin interfacegroovy.lang.GroovyObject- Overrides:
invokeMethodin classgroovy.lang.GroovyObjectSupport
-
setProperty
public void setProperty(java.lang.String name, java.lang.Object value)- Specified by:
setPropertyin interfacegroovy.lang.GroovyObject- Overrides:
setPropertyin classgroovy.lang.GroovyObjectSupport
-
_getProperty
private java.lang.Object _getProperty(java.lang.String name)
-
append
private void append(java.lang.String key, java.lang.Object value)
-
_append
private void _append(java.lang.String key, java.lang.Object value, JSON target)
-
createArray
private JSON createArray(java.util.List list)
-
createObject
private JSON createObject(groovy.lang.Closure closure)
-
createObject
private JSON createObject(java.util.Map map)
-
createObject
private JSON createObject(java.lang.String name, java.lang.Object arg)
-
-