My project is based on Java 8 and uses Spring throughout I have a service that returns a bean which contains a list of beans in it.
Here is the code API Method
@RequestMapping(value = "/search",", produces = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST)
@ResponseBody
public DeferredResult<EmpAdvancedSearchPageBean> getSearch(
@RequestBody final EmpBean empBean) {
LOGGER.info("Pre getSearch");
EmpSearchPageBean searchPageBean = dataService.getSearch(empBean);
LOGGER.info("Post getSearch");
LOGGER.info("Pre set deffered result");
DeferredResult<EmpSearchPageBean> deferredResult = new DeferredResult<>();
deferredResult.setResult(searchPageBean);
LOGGER.info("Post set deffered result");
return deferredResult;
}
EmpSearchPageBean
public class EmpSearchPageBean implements java.io.Serializable {
private static final long serialVersionUID = 8085664391632415982L;
@JsonProperty("draw")
private Integer draw;
@JsonProperty("recordsTotal")
private Integer recordsTotal;
@JsonProperty("recordsFiltered")
private Integer recordsFiltered;
@JsonProperty("data")
private List<EmpSearch> data;
}
EmpSearch
public class EmpSearch implements java.io.Serializable {
private static final long serialVersionUID = -7665557350420327753L;
@JsonProperty("divisionDesc")
private String divisionDesc;
@JsonProperty("corpId")
private String corpId;
@JsonProperty("businessUnitDesc")
private String businessUnitDesc;
@JsonProperty("fdirName")
private String fdirName;
}
If the list of data ( List data; ) contains 500 records - this service returns in about 2 seconds However if it contains around 2000 records (which is a common use case), it can take up to 2 minutes to return
Based on my log statements - it takes about 2 seconds to return this data from the database and the rest of the time is taken up producing the json.
I am using Spring Web version 4.3.3.RELEASE. from the debug logs I can see that it is using the class org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
Can anyone offer any advise on what I need to do in order to render large quantities of json data successfully?
Decided to refactor code to not return as much json data. Tried multiple suggestions based on question feedback but did not get the required gains