【发布时间】:2019-06-30 10:46:28
【问题描述】:
我从 Postman 发送了正确的 JSON 格式正文。
{
"loginId": "xxxxxx",
"password": "xxxxxx",
"clientIP": "xxxxx",
"companyId": "xxxxx"
}
这是我的控制器
@RestController
@RequestMapping(path = "/umm")
public class LoginServer {
private transient Logger log = LogManager.getLogger(this.getClass());
@RequestMapping(value = "/basicLogin",method = RequestMethod.POST)
public @ResponseBody LoginRequest login(@RequestBody(required = true) LoginRequest loginRequest){
return null;
}
}
这是我的域名
public class LoginRequest implements Serializable {
private static final long serialVersionUID = -884241731093688658L;
private String loginId;
private String password;
private String clientIP;
private String companyId;
public LoginRequest(String loginId, String password, String clientIP, String companyId) {
this.loginId = loginId;
this.password = password;
this.clientIP = clientIP;
this.companyId = companyId;
}
//getter and setter omitted
}
我不知道为什么它返回 400 错误代码(错误请求),因为我发送了正确的 JSON 正文
这是响应消息。
{
"timestamp": 1549458416991,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "JSON parse error: Can not construct instance of escf.api.domain.login.LoginRequest: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of escf.api.domain.login.LoginRequest: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)\n at [Source: java.io.PushbackInputStream@1c360a55; line: 2, column: 2]",
"path": "/umm/basicLogin"
}
我需要它返回代码 200。
【问题讨论】:
-
请显示完整的请求和完整的响应,应该有错误信息
-
好的,现在知道了。
-
阅读响应中的消息。它会准确地告诉您要解决的问题。
-
我创建了完全相同的 Controller 和 LoginRequest 类,它对我来说非常好用。
-
我添加了 super();在域类中它对我有用。
标签: json spring spring-boot postman