Spring Rest API - JSON response got cut in half

81 views Asked by At

I'm working on uniforming some of our existing rest API. For the response, I created a generic function using the HttpServletResponse writer. It looks something like this:

public static void writeJSONResponse(String message, HttpServletResponse response) throws IOException {
        response.addHeader("Content-Type", "application/json");
        GenericAPIResponseJsonSchema jsonResponse = new GenericAPIResponseJsonSchema();
        try {
            jsonResponse.setMessage(message);
        } catch (JSONException e) {
            log.debug(e.getMessage());
        }
        response.getWriter().write(JSONObject.wrap(jsonResponse).toString());
    }

GenericAPIResponseJsonSchema is just a simple POJO with a string Message nothing fancy.

The problem is all the response is now being returned with their content cut off (not exactly - but you get what I mean) in half. For example, I'm getting:

{ "message":"Invalid

Instead of

{ "message":"Invalid attribute name" }

If I try to set the response content length to match the exact result it will then come back as "Error aborted". Setting the message to something very short like: "MSG" will also result in the same error.

I'm using this function for multiple other APIs and some of them are working fine. There's practically no difference that I have spotted between those that work and those that don't. I'm out of ideas, any suggestions?

0

There are 0 answers