How about
def var = Eval.me("[1,2,3]")
assert var.class == ArrayList
NP Dean. I suppose the security implications are pretty big in that case. Try running Eval.me("System.exit(0)") in the groovyConsole and you’ll see what I mean. You might want to have the client pass a JSON string instead which could be easily parsed into a list, and will throw an exception if it’s invalid json.
-Kal
Or if you know it’s always going to be a list like that you could do something ugly like
def clientString = "[1,2,3,4,5]"
ArrayList myList = clientString.replaceAll("\\[","").replaceAll("]","").split(",")
assert myList.class == ArrayList
myList.each{
println "${it} [${it.class}]"
}
Or if you know it’s always going to be a list like that you could do something ugly like
def clientString = "[1,2,3,4,5]"
ArrayList myList = clientString.replaceAll("\\[","").replaceAll("]","").split(",").