当从 B 类的 ResponseEntity 中的控制器返回响应时。但它返回空的 json 响应。控制器方法如下:
@PostMapping("/test")
public ResponseEntity testSave(@Valid @RequestBody ReqData req, BindingResult result)
{
B response;
if(result.hasErrors())
{
response=generateBadRequestResponse(result);//response variable of B type holds value in its fields, but not sending in response
return ResponseEntity.ok(response); //getting empty json in postman response
}
return ResponseEntity.ok(response);
}
而 B 类声明如下:
public class B <T> implements Serializable {
private String message;
private T body;
private List<T> errorList= new ArrayList<>();
//omitted unnecessary code for brevity
}
我测试了邮递员的api。