I am developing a rest controller to download a .docx file into the client system. My code is working fine as the file is getting downloaded. Now I want to enhance the response. My requirement is to also send a JSON payload in the response along with the .docx file content, something like

```
{"message":"Report downloaded Successfully"}

```

incase of successful download or with a different message incase of failure.

Below is my restcontroller code:

```
@RestController
public class DownloadController {

    @PostMapping(value="/download",
            consumes = {"multipart/form-data"},
            produces = {"application/octet-stream"})
    public ResponseEntity<?> downloadFile(@RequestParam("file") MultipartFile uploadFile){

        //business logic to create the attachment file

        try {

            File file = new File("path_to_.DOCX file_I_have_created");
            byte[] contents = Files.readAllBytes(Paths.get(file.getAbsolutePath()));

            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
            headers.setContentDisposition(ContentDisposition.attachment().filename("survey.docx").build());

            return new ResponseEntity<>(contents, headers, HttpStatus.OK);
        } catch (Exception e){
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

}

```

How do I modify my response code to send both the JSON message and the byte[] contents so that the file gets downloaded and I can see the JSON message in the response preview tab in the chrome or response body in postman?

UPDATE: I tried to define a response class like below

```
public class Downloadresponse {

private byte[] content;
private String message;

//getter,setters

}

```

With this change in place, I am getting below exception:

```
Resolved [ HttpMessageNotWritableException: No converter for [class ...Downloadresponse] with preset content-type "application/octet-stream”]

```