好吧,我正在尝试在 spring 控制器中检索嵌套的 json 并收到 400(错误请求)错误。
JSON
{"AuthenticationInfo":
{"loginId":"243324","password":"xyz"}
}
控制器
@RequestMapping(value = "/login", method = RequestMethod.POST,headers={"Accept=*/*","content-type=application/json"})
@ResponseBody
public MySubscriber getSubscriber(@RequestBody MyAuthentication myAuthentication) {
LOGGER.log(Level.INFO, "getSubscriber");
System.out.println("getSubscriber method : "+myAuthentication);
MySubscriber mySubscriber = helloWebService.getSubscriber(myAuthentication);
LOGGER.log(Level.INFO, "mySubscriber : " + mySubscriber);
System.out.println( "mySubscriber : " + mySubscriber);
return mySubscriber;
}
我的身份验证
public class MyAuthentication extends AuthenticationInfo {
private AuthenticationInfo AuthenticationInfo;
public AuthenticationInfo getAuthenticationInfo() {
return AuthenticationInfo;
}
public void setAuthenticationInfo(AuthenticationInfo authenticationInfo) {
AuthenticationInfo = authenticationInfo;
}
@Override
public String toString()
{
return "AuthenticationInfo : "+AuthenticationInfo;
}
}
身份验证信息
public class AuthenticationInfo {
private String loginId;
private String password;
public String getLoginId() {
return loginId;
}
public void setLoginId(String loginId) {
this.loginId = loginId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString()
{
return "{ loginId : "+loginId+" || password"+password+"}";
}
}
当我只触发简单的 Json 并相应地检索它时,错误就会发生。这里唯一的问题是 Json 的嵌套结构