我正在尝试测试POST路由(在Playframework 2.1 / Java上)并继续收到错误请求 - 无效的JSON响应。
请让我知道我做错了什么。我的测试代码如下。
running(fakeApplication(), new Runnable() {
public void run() {
Map map = new HashMap();
map.put("key1", "val1");
map.put("key2", 2);
map.put("key3", true);
JsonNode df= Json.toJson(map);
Result result = route
(fakeRequest(POST, "/item").withHeader("Content-Type", "application/json").withSession(AccountTest.USER_KEY, "some key")
.withSession(AccountTest.PROVIDER_KEY, "facebook").withJsonBody(df));
Logger.debug("result is " + contentAsString(result));
System.out.println("result is " + contentAsString(result));
assertThat(result).isNotNull();
// assertThat(result).isNotNull();
// assertThat(result).isEqualTo("hello");
}
});
答案 0 :(得分:2)
这是Play 2.1(Java)中记录的错误。请参阅此处的错误和git-pull请求https://play.lighthouseapp.com/projects/82401/tickets/984-adding-json-body-to-play-21-java-returns-invalid-json-message#ticket-984-8