@RequestMapping(method = RequestMethod.GET, value = "/all") public void getAllEarnings(HttpServletRequest request, HttpServletResponse response) throws JsonGenerationException, JsonMappingException, IOException { log.info("Retrieving earnings..."); List<Earning> l = earningsService.getEarnings(); log.info("Write JSON in the output stream of the servlet"); response.setContentType(MediaType.APPLICATION_JSON_VALUE); new ObjectMapper().writeValue(response.getOutputStream(), l); }