简体   繁体   English

无法使用Jersey获得完整的JSON

[英]Cannot get a fully JSON using jersey

I'm trying to read a json by using jersey api. 我正在尝试使用Jersey API读取json。 That's a long json. 那是一个很长的json。 The problem is I can't get the full json. 问题是我无法获取完整的json。 Please look at both links below for more understanding. 请查看下面的两个链接以了解更多信息。

Expect result. 期待结果。 (10 objects) (10个物件)

Actual result (Sorry because this one can't be format. But it can only get 4 objects and a bit of the 5th object.) 实际结果 (很抱歉,因为该格式无法设置。但是只能得到4个对象和第5个对象的一部分。)

This is my code to get json: 这是我获取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;

I don't know what I did wrong here. 我不知道我在这里做错了什么。

Your client is receiving the full output. 您的客户正在收到完整的输出。 You are seeing the truncated output in the log because the LoggingFilter that you have enabled by default will truncate the output. 您会在日志中看到截断的输出,因为默认情况下启用的LoggingFilter会截断输出。

Check the constructors here for how to set the maxEntitySize. 在此处检查构造函数,以了解如何设置maxEntitySize。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM