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.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 Summary
FieldsModifier and TypeFieldDescriptionprivate JSON
private static final String
private JsonConfig
private Map
private Stack
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private Object
_getProperty
(String name) private void
private JSON
createArray
(List list) private JSON
createObject
(groovy.lang.Closure closure) private JSON
createObject
(String name, Object arg) private JSON
createObject
(Map map) getProperty
(String name) invokeMethod
(String name, Object arg) void
setJsonConfig
(JsonConfig jsonConfig) void
setProperty
(String name, Object value) Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
-
Field Details
-
JSON
- See Also:
-
current
-
properties
-
stack
-
jsonConfig
-
-
Constructor Details
-
JsonGroovyBuilder
public JsonGroovyBuilder()
-
-
Method Details
-
getJsonConfig
-
setJsonConfig
-
getProperty
- Specified by:
getProperty
in interfacegroovy.lang.GroovyObject
- Overrides:
getProperty
in classgroovy.lang.GroovyObjectSupport
-
invokeMethod
- Specified by:
invokeMethod
in interfacegroovy.lang.GroovyObject
- Overrides:
invokeMethod
in classgroovy.lang.GroovyObjectSupport
-
setProperty
- Specified by:
setProperty
in interfacegroovy.lang.GroovyObject
- Overrides:
setProperty
in classgroovy.lang.GroovyObjectSupport
-
_getProperty
-
append
-
_append
-
createArray
-
createObject
-
createObject
-
createObject
-