Hello all,
I noticed that in Spring, there is a class name ResponseBodyAdvice
help us to intercept and change content of response before it return to client.
This is an example:
public class ControllerAdvice implements ResponseBodyAdvice<Object> {
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
return true;
}
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
ServerHttpResponse response) {
ResponseWrapper responseWrapper = new ResponseWrapper(body);
responseWrapper.setStatusCode(200);
return responseWrapper;
}
}
With this snippet, I can only return the actual data I’d like to return, and the snippet will handle wrapping the actual data to wrapper object.
Is there any way to implement that in Play?
Thank you so much!