Streaming JSON responses

Preparing the result of an HTTP call may lead to storing a lot of objects on the server side and thus triggering more garbage collection by the JVM than needed. To keep a lower memory footprint, there is the possibility of streaming the results.

We will get the list of friend's names of someone whose name is given as a parameter.

Create a new class with this code:

package learningneo4j;import org.codehaus.jackson.JsonEncoding;import org.codehaus.jackson.JsonGenerator;import org.codehaus.jackson.map.ObjectMapper;import java.io.IOException;import java.io.OutputStream;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.WebApplicationException;import javax.ws.rs.core.Context ...

Get Learning Neo4j 3.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.