3

我正在尝试测试 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");
            }

        });
4

1 回答 1

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-消息#ticket-984-8

于 2013-02-15T22:40:39.903 回答