- All Implemented Interfaces and Traits:
- ResponseBodyAdvice<OperationResponse<?>>, ApplicationContextAware
@CompileStatic
class ResponseFormattingResponseBodyAdvice
extends Object
implements ResponseBodyAdvice<OperationResponse<?>>, ApplicationContextAware
Handles shaping and internationalization of the body in HTTP JSON responses when successful result of controller execution is OperationResponse instance.
Produced HTTP response body is a modified instance of OperationResponse where modifications only affect "metaData
", while "payload
" is left unchanged.
"metaData
" is affected by adding HttpResponseMetaData into it.
When serialized into JSON it looks something like following example ("payload
" is left out since it is not affected):
{
"metaData": {
"general": {
"severity": "info",
"locale": "en_GB",
"timestamp": "2020-04-27T06:13:09.225221Z"
},
"http": {
"status": "200",
"message": "OK"
}
},
"payload": {
...
}
}
When used from Spring Boot application, the easiest is to create controller advice and register it with the spring context:
@ControllerAdvice
class ResponseFormattingResponseBodyAdviceControllerAdvice extends ResponseFormattingResponseBodyAdvice {
}
@Configuration
class SpringBootConfig {
@Bean
ResponseFormattingResponseBodyAdviceControllerAdvice responseFormattingResponseBodyAdviceControllerAdvice() {
return new ResponseFormattingResponseBodyAdviceControllerAdvice()
}
}