Reputation: 177
How to convert string of collections to collections
example variables:
string_txt = "[id:2,name:'myname',age:'20']"
i want use it as instances:
string_txt.id >> 2
string_txt.name >> "myname"
...
Upvotes: 0
Views: 54
Reputation: 171084
You can use the Eval
class:
def stringTxt = "[id:2,name:'myname',age:'20']"
def map = Eval.me( stringTxt )
assert map.name == 'myname'
Of course, if there's another way of doing it other than putting the Map into a String, you should probably do that. Evaluating text has the potential to be a large security risk :-(
Upvotes: 2