Is there a way to print a Groovy Collection out in a pastable format?

jeremyjjbrown

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.

cfrick

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Groovy是否具有Collection的size属性?

来自分类Dev

从groovy w / out超时执行shell命令

来自分类Dev

从groovy w / out超时执行shell命令

来自分类Dev

Is there a way to print all velocity context?

来自分类Dev

Creating primitive array out of wrapper collection in java

来自分类Dev

首选的System.out.print()或System.out.printf()?

来自分类Dev

print out 5 characters in a line bash scripting

来自分类Dev

嵌套的“ System.out.print”输出

来自分类Dev

Print out all possible fixed length words

来自分类Dev

System.out.print导致延迟?

来自分类Dev

Out.Print方法不起作用?

来自分类Dev

print(* args,** kwargs)vs print(“ {},{}”。format(* args,** kwargs))

来自分类Dev

format r(repr) of print in python3

来自分类Dev

How to format Mongoose debug output - pretty print

来自分类Dev

List out declared methods of a Groovy class from Java

来自分类Dev

从Groovy调用具有IN OUT参数类型的Oracle过程

来自分类Dev

Is there any way to find out the tables relationship?

来自分类Dev

Why does my sort print out multiple lists?

来自分类Dev

How to print out the file name and line number of the test in python nose?

来自分类Dev

是System.out.print中和FXML报表如何使用“%”符号

来自分类Dev

out.print出现在html标记之外

来自分类Dev

测试程序中的调试语句的Logger或System.out.print

来自分类Dev

无法比较out.print()返回的字符串

来自分类Dev

我如何在System.out.print中收集int

来自分类Dev

查找System.out.print的正则表达式

来自分类Dev

java System.out.print格式样式

来自分类Dev

System.out.print 不显示客户数据

来自分类Dev

An efficient way to convert document to pdf format

来自分类Dev

为什么print(“ {}”)。format()有效的语法?

Related 相关文章

热门标签

归档