Vadym Kovalenko
Vadym Kovalenko

Reputation: 699

Groovy string to HashMap cast

As you know, we can simply obtain a string from a hash using the toString() method. So we get string similar to this:

[first:[one:1.1], second:2]

The question is, how can we cast this string to hash again?

Upvotes: 3

Views: 3902

Answers (1)

tim_yates
tim_yates

Reputation: 171084

You can use the Eval.me static method:

def map = Eval.me( '[first:[one:1.1], second:2]' )
assert map == [first:[one:1.1], second:2]

Upvotes: 8

Related Questions