Serializing groovy map to string with quotes

Groovy provides the inspect() method returns an object as a parseable string:

// serialize
def m = [a: 123, b: 'test']
def str = m.inspect()

// deserialize
m = Eval.me(str)

Another way to serialize a groovy map as a readable string is with JSON:

// serialize
import groovy.json.JsonBuilder
def m = [a: 123, b: 'test']
def builder = new JsonBuilder()
builder(m)
println builder.toString()

// deserialize
import groovy.json.JsonSlurper
def slurper = new JsonSlurper()
m = slurper.parseText('{"a": 123, "b": "test"}')

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)