I routinely have to mock some data responses for unit testing purposes. I'd like to be able to collect a real response and put it in a mock. But Groovy prints out Collections without enclosing the string values.
def foo = ["foo":"bar"]
println foo
def bar = ["foo","bar"]
println bar
returns
[foo:bar]
[foo, bar]
So when I have a huge and complex json structure to work with I have to spend a long time in tedious and error prone editing. I could probably write a recursive function to print this for me but I was curious if there was a trivial way to do it first.
for trivial datatypes there is inspect
:
def m = [a:'a', b:42, c:[1,2,3]]
def d = m.inspect()
assert d=='''['a':'a', 'b':42, 'c':[1, 2, 3]]'''
m2 = Eval.me(d)
assert m==m2
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句