0

I have to return byte[] as file data and JSON object both in a http response from a REST service.

Also I have to process this response in Angular 6 at front end side

The REST service uses Jersey 2.0

I have already implemented the Jersey Rest Service and it returns Multipart Response

But I am unable to process the Multipart response in Angular 6 as HttpClient in Angular cannot process MultiPart Response as per Handling a multipart Response body in Angular

Now , I have done exactly same thing in Spring by using org.springframework.util.MultiValueMap as below -

MultiValueMap<String, Object> responseData = new LinkedMultiValueMap<String, Object>();  
SomeDto someDto = new SomeDto();
responseData.add("results", someDto); // this is JSON 
responseData.add("fileDetails", fileData); // where fileData has one of the field 
as byte[] 

So I am able to return byte[] as well as Java Object in same Http Response.

Finally the response received at client side is JSON

How can we achieve the same thing in Jersey 2 ?

Is there any MultiValueMap counterpart in Jersey 2 which can be used to send both byte[] and Java Object in Jersey 2 ?

Atul
  • 1,560
  • 5
  • 30
  • 75

0 Answers0