About Me

Mein Bild
Freelancing software developer / architect, mobile geek. Topics: Software technologies (java, groovy, agile), politics, web, science, green, mobile, android.
Homepage: www.tutaona.com

"The absence of limitations is the enemy of art." - Orson Welles

Montag, 25. Juni 2012

Easy JSON Building

def p = new Expando(
    name:'Mary', 
    pets:[
        new Expando(name:'Fido', species:'Dog'),
        new Expando(name:'Snickers', species:'Cat')
    ]
)

def json = new JsonBuilder()
json( {
    name p.name,
    pets( p.pets.collect {[
        name:it.name,
        species:it.species
    ]})
})
JsonOutput.prettyPrint(json.toString())

Keine Kommentare:

Kommentar veröffentlichen