Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem while returning a ResponseEntity<byte[]> from REST API. Why?

When, I return ResponseEntity<byte[]>(new ResponseEntity<byte[]>(sb.toString().getBytes(), headers, HttpStatus.OK)) from REST API, it takes about 6 seconds but when I return responseEntity.getBody(), it takes about 1 seconds. How ?

ResponseEntity<byte[]> responseEntity = configTemplateService.getConfigTemplateExample(type);
// This need very long time
return responseEntity;
ResponseEntity<byte[]> responseEntity = configTemplateService.getConfigTemplateExample(type);
// This need less time
return responseEntity.getBody();
like image 570
peng Avatar asked Nov 19 '25 11:11

peng


1 Answers

Data type of responseEntity.getBody() is String (1).

Data type of responseEntity is binary data (2) including Body and another parts those are not Body (such as Header).

(2) = (1) + (another parts)

therefore, (2) > (1)

like image 129
Do Nhu Vy Avatar answered Nov 22 '25 00:11

Do Nhu Vy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!