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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.