Skip to content
Advertisement

Create structured archive with files in java

I want to implement GET api that returns ZIP file.

I defined api using openapi

JavaScript

As far as I understand my api should return byte[], so my controller looks like below

JavaScript

Is it ok to return byte[] or it should be some stream, end user will get the zip?

Implementation.

I have map of objects that I am parsing using Jackson object mapper.

How I could create folder structure and place files with json outputs from object mapper. Zip it and return to the caller.

Example:

JavaScript

Advertisement

Answer

Just use ZipOutputStream, and wrap it around a ByteArrayOutputStream:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement