我有一个巨大的 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.
我可以通过读取文件并将正文作为字符串传递来运行,这可行,但我发现我可以直接传递文件对象,但这行不通。
经过充分研究后,它似乎不起作用。我放心地打开了问题。 https://github.com/jayway/rest-assured/issues/674
最佳答案
与放心的团队发布问题后。我有办法解决。我测试了修复程序,现在问题已解决。
安心寄语:
它现在应该已修复,所以我现在部署了一个应该可以解决此问题的新快照。请在添加以下 Maven 存储库后尝试版本 2.9.1-SNAPSHOT:
<repositories>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots />
</repository>
</repositories>
更多信息:https://github.com/jayway/rest-assured/issues/674#issuecomment-210455811
关于java - 在 Rest-assured 中使用 Json 文件作为负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36579155/