I'm using Dropwizard 0.9.1 in my application and I have a GET-Method returning a ChunkedOuput like described here. MediaType should be APPLICATION_JSON and it works but the result is not a valid JSON.
Here is the example Ressource:
@GET
@Path("/chunktest")
@Produces(MediaType.APPLICATION_JSON)
public class AsyncResource {
@GET
public ChunkedOutput<MyCustomObject> getChunkedResponse() {
final ChunkedOutput<MyCustomObject> output = new ChunkedOutput<MyCustomObject>(MyCustomObject.class);
new Thread() {
public void run() {
try {
MyCustomObject chunk;
while ((chunk = getNextCustomObject()) != null) {
output.write(chunk);
}
} catch (IOException e) {
// IOException thrown when writing the
// chunks of response: should be handled
} finally {
output.close();
// simplified: IOException thrown from
// this close() should be handled here...
}
}
}.start();
// the output will be probably returned even before
// a first chunk is written by the new thread
return output;
}
private MyCustomObjectgetNextCustomObject() {
// ... long running operation that returns
// next object or null
}
}
Now if I try curl this non-valid JSON is returned:
HTTP/1.1 200 OK
Date: Thu, 19 Nov 2015 13:08:28 GMT
Content-Type: application/json
Vary: Accept-Encoding
Transfer-Encoding: chunked
{
"key1" : "value1a",
"key2" : "value2a"
}{
"key1" : "value1b",
"key2" : "value2b"
}{
"key1" : "value1c",
"key2" : "value2c"
}{
"key1" : "value1d",
"key2" : "value2d"
}
I also tried to use a chunk delimiter but with this I can only fix the "," between the chunk-JSON's, but I have no idea how to insert the start/end brackets
{
and
}
Does anyone know how to fix this?