gamo
gamo

Reputation: 1567

Cannot get a fully JSON using jersey

I'm trying to read a json by using jersey api. That's a long json. The problem is I can't get the full json. Please look at both links below for more understanding.

Expect result. (10 objects)

Actual result (Sorry because this one can't be format. But it can only get 4 objects and a bit of the 5th object.)

This is my code to get 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.

Upvotes: 1

Views: 604

Answers (1)

Chris Hinshaw
Chris Hinshaw

Reputation: 7255

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.

Check the constructors here for how to set the maxEntitySize.

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

Upvotes: 1

Related Questions