Using Spring Boot by default the controllers return minified JSON, but for some requests the response should be pretty formatted, if special request argument is passed. For example:
http://test.com/health => returns minified JSON
http://test.com/health?pretty => returns pretty formatted JSON
How to extend the request mapping handler/controller to optionally format the output and keep the produced mime type application/json
?
@RequestMapping(
value = {"/health", "/"},
produces = APPLICATION_JSON_VALUE)
public ResponseEntity<?> checkHealth(@RequestParam(required = false, value = "pretty") String prettyapplicationInfo) {
final Map<String, Object> response = getResponse();
if (pretty != null) {
// so, how to format the response, if "pretty" property is specified?
}
return new ResponseEntity<>(response, HttpStatus.OK);
}