Skip to content

Instantly share code, notes, and snippets.

@ivanarrizabalaga
Created April 22, 2014 09:16
Show Gist options
  • Save ivanarrizabalaga/11171419 to your computer and use it in GitHub Desktop.
Save ivanarrizabalaga/11171419 to your computer and use it in GitHub Desktop.
Turning groovy objects into maps
//Couple of VO classes
class ParamsContainerA{
int num1
String text1
boolean bool1
}
class ParamsContainerB{
int num2
String text2
boolean bool2
}
//Couple of instances
ParamsContainerA anObjA=new ParamsContainerA(num1:12,text1:"holaA",bool1:true)
ParamsContainerB anObjB=new ParamsContainerB(num2:24,text2:"adiosB",bool2:false)
//Turned into Maps (filtering out the class property if desired)
Map mA=anObjA.properties.findAll{it.key!="class"}
Map mB=anObjB.properties.findAll{it.key!="class"}
Map result=mA+mB
println mA
println mB
println result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment