java使用Json文件重启负载
我有一个巨大的JSON文件作为rest api调用的有效负载发布,用于测试目的。我试过这样的方法:
public void RestTest() throws Exception {
File file = new File("/Users/bmishra/Code_Center/stash/experiments/src/main/resources/Search.json");
String content = null;
given().body(file).with().contentType("application/json").then().expect().
statusCode(200).
body(equalTo("true")).when().post("http://devsearch");
}
并得到如下错误:
java.lang.UnsupportedOperationException: Internal error: Can't encode /Users/bmishra/Code_Center/stash/experiments/src/main/resources/Search.json to JSON.
我可以通过读取文件并将正文作为字符串传递来运行,这是可行的,但我看到我可以直接传递file对象,但这不起作用
经过充分研究,它似乎不起作用。我已经放心地提出了这个问题。 https://github.com/jayway/rest-assured/issues/674
# 1 楼答案
我使用一种通用方法读取json并将其作为字符串发送,即:
在你的例子中: