0

We are using spring boot v2.7.1. For json conversions we are using inbuilt provided jackson. Problem statement: In a particular REST API call, we have nested POJOs, which when converted to json generate 3-5 MB of JSON. Question/Challenge: This rest API call takes ~500ms. Out of which the service layer (populating of POJO) takes around 50 to 100 ms, but remaining 400 ms are taken in POJO to json conversion when sending response

Sample code

@RequestMapping(path = "/generate/big-json", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<BigResponse> generateBigResponse(@PathVariable("id") String id) {
        
                BigResponse bigResponse = bigService.getBigResponse(id);
                //the above service gets processed in 50-100 ms.
        return new ResponseEntity<>(bigResponse, HttpStatus.OK); 
    } 

Kindly advise if there is any way, I can reduce the 400 ms of POJO to JSON conversion time taken by springboot (or jackson internally).


Edit1:

After using blackbird (recommended for java 11+), i saw following response times (in milli seconds). Still quite high.
Median : Vanilla: 320 ms vs Blackbird 284 ms
Note: In all runs, the same json was used of ~3 MB in size.
Well, my question was more on the lines of What's the best way to convert pojo to JSON in Spring but the thread doesn't provide any proper answer.
Please guide on any suggestions for improvements.

0 Answers0