我已经构建了一个错误控制器,它应该是我在Spring REST服务中捕获异常的"最后一行".但是,我似乎无法将POJO作为响应类型返回.为什么杰克逊不为这个案子工作?
我的班级看起来像:
@RestController
public class CustomErrorController implements ErrorController
{
private static final String PATH = "/error";
@Override
public String getErrorPath()
{
return PATH;
}
@RequestMapping (value = PATH)
public ResponseEntity<WebErrorResponse> handleError(HttpStatus status, HttpServletRequest request)
{
WebErrorResponse response = new WebErrorResponse();
// original requested URI
String uri = String.valueOf(request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI));
// status code
String code = String.valueOf(request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE));
// status message
String msg = String.valueOf(request.getAttribute(RequestDispatcher.ERROR_MESSAGE));
response.title = "Internal Server Error";
response.type = request.getMethod() + ": " + uri;
response.code = Integer.valueOf(code);
response.message …Run Code Online (Sandbox Code Playgroud)