Skip to content

Instantly share code, notes, and snippets.

@thetekst
Last active November 12, 2018 08:10
Show Gist options
  • Save thetekst/937738db522670b9fc9bc49395096d25 to your computer and use it in GitHub Desktop.
Save thetekst/937738db522670b9fc9bc49395096d25 to your computer and use it in GitHub Desktop.
groovy script. Convert object with map attribute to json
def testMapToJson() {
def obj = new DictionaryRow()
obj.id = 1L
obj.values = [
(new DictionaryField().setId(1)) : 1,
(new DictionaryField().setId(2)) : 2] as Map
println new JsonBuilder(obj).toPrettyString()
}
testMapToJson()
/*
{
"created": null,
"values": {
"DictionaryField(id=1, name=null, created=null, lastUpdated=null, key=null)": 1,
"DictionaryField(id=2, name=null, created=null, lastUpdated=null, key=null)": 2
},
"id": 1,
"dictionary": null,
"lastUpdated": null
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment