My application is built using Spring boot (1.3.3.RELEASE) with Spring mvc, Spring jpa hibernate data. MySql is the database, and Jackson is the Json serializer. On java 8.
I want to return a huge dataset to my controller method. Instead of fetching all the data and then going to the jackson serializer, I want to return a stream of objects, as shown below:
@RequestMapping(value = "/candidates/all", method = RequestMethod.GET) public Stream<Candidate> getAllCandidates(){ try { return candidateDao.findAllByCustomQueryAndStream(); } catch(Exception e){ LOG.error("Exception in getCandidates",e); } return null; }
my DAO is as follows:
@Query("select c from Candidate c") public Stream<Candidate> findAllByCustomQueryAndStream();
However, Jackson serializes the stream object instead of the contents of the stream. Actual result below:
{"parallel" : false}
How can I train Jackson to serialize content, not a stream object?
java rest jackson spring-mvc java-stream
Vasco
source share