无法使用泽西获得完全JSON

时间:2015-08-11 09:15:37

标签: java json jersey

我正在尝试使用jersey api阅读json。那是一个很长的json。 问题是我无法获得完整的json。请查看以下两个链接以获得更多理解。

Expect result.(10个对象)

Actual result(很抱歉,因为这个格式不能格式化。但它只能获得4个对象和第5个对象。)

这是我获取json的代码:

    Client client = Client.create();
    WebResource resource = client.resource(url);
    ClientResponse clientResponse = resource.accept("application/json").get(ClientResponse.class);

    if(clientResponse.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + clientResponse.getStatus());
    }

    String output = "";
    String response = "";

    BufferedReader br = new BufferedReader(new InputStreamReader(
            (clientResponse.getEntityInputStream())));

    while ((output = br.readLine()) != null) {
        response = response + output;
    }

    br.close();

    return response;

我不知道我在这里做错了什么。

1 个答案:

答案 0 :(得分:1)

您的客户正在接收完整输出。您在日志中看到截断的输出,因为默认情况下启用的LoggingFilter将截断输出。

检查构造函数,了解如何设置maxEntitySize。

https://jersey.java.net/apidocs/2.11/jersey/org/glassfish/jersey/filter/LoggingFilter.html