java - 无法使用 jersey 获取完整的 JSON

标签 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;

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

最佳答案

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

检查此处的构造函数以了解如何设置 maxEntitySize。

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

关于java - 无法使用 jersey 获取完整的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31937742/

相关文章:

java - ClasscastException : MyClass cannot be cast to javax. servlet.Filter

java - 从命令行运行 jar 时出现 MessageBodyProviderNotFoundException

java - 在数组中查找加起来等于给定总和的非重复对

java - 使用ant时出现NoClassDefFoundError

java - Hashicorp Vault - 无法识别的 SSL 消息,明文连接?

javascript - 如何在 MVC 中为图表实现动态数据?

ruby-on-rails - Ruby 解析 : Error when I trying to put Cyrillic symbols into URL request

javascript - 使用 Google Sheets Apps 脚本访问 Telegram 机器人菜单的示例 1

java - 具有多个路径的 Jersey 资源

java - 是否可以通过 Jersey AsyncResponse 设置 cookie