Last active
November 12, 2018 08:10
-
-
Save thetekst/937738db522670b9fc9bc49395096d25 to your computer and use it in GitHub Desktop.
groovy script. Convert object with map attribute to json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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