0

Have the following Spring REST code which returns a JSON response-

@RequestMapping(value="/viewAllEmployees.do")
    @ResponseBody
    public List<Employee> viewAllItems() {
        List<Employee> allEmployees = employeeService.getAllEmployees();
        return allEmployees;
    }

How can this be modified to return the JSON response as a zip? Thanks

1 Answers1

0

Maybe you could try to set "application/zip" as produces in request mapping. This should treat it as header.

@RequestMapping(value="/viewAllEmployees.do", produces="application/zip")
public byte[] viewAllItems() {
...

You can check how to convert to zip: Spring REST - create .zip file and send it to the client

Community
  • 1
  • 1
chmielu
  • 1
  • 2
  • Thanks chmielu..So the JSON data will be required to change to byte[] while returning response? –  Oct 11 '16 at 13:12
  • Yes. Try to check this link it might be the answer. http://stackoverflow.com/questions/27952949/spring-rest-create-zip-file-and-send-it-to-the-client I would save the Json response in to tmp file and then fallow the steps in the link – chmielu Oct 11 '16 at 13:15
  • Or you can put the JSON response into stream and copy to ZipOutputStream – chmielu Oct 11 '16 at 13:25