返回JSON时清空数组响应

时间:2017-12-04 15:51:44

标签: javalite activeweb

我尝试从控制器返回记录列表,如下所示:

public class ListsController extends APIController  {

    public void index(){
        respond(List.findAll().toJson(true)).contentType("application/json");
    }
}

ApiController的定义如下:

public abstract class APIController extends AppController {
    @Override
    protected String getContentType() {
        return "application/json";
    }

    @Override
    protected String getLayout() {
        return null;
    }

}

当我测试时:

@Test
    public void shouldRenderLists(){
        app.models.List list = new app.models.List();
        list.set("id", 1);
        list.set("code", "some code");
        list.set("name", "some name");
        list.set("item_code", "some item code");
        list.saveIt();
        request().integrateViews().get("index");

        the(contentType()).shouldBeEqual("application/json");
        Map[] listsMaps = JsonHelper.toMaps(responseContent());

        the(listsMaps.length).shouldBeEqual(1);
        Map listEntry = listsMaps[0];

        the(listEntry.get("code")).shouldBeEqual("some code");
        the(listEntry.get("name")).shouldBeEqual("some name");
    }

失败,因为responseContent()返回[\n\n]。任何想法为什么会这样?

0 个答案:

没有答案