當我在@RequestBody中使用帶繼承的類時,我得到'400 Bad Request'。我有另一個控制器,我使用沒有繼承的類,它的工作原理。Spring MVC - 使用@RequestBody收到的對象限制
我想知道我是否可以在@RequestBody中使用常規EJB,或者對可以使用的類有任何限制嗎?
下面是控制器:
@RequestMapping(value = "auth/ping", method = RequestMethod.POST, consumes="application/json")
@ResponseStatus(HttpStatus.OK)
public @ResponseBody String pingPost(@RequestBody User model) {
final String signature = CLASSNAME + "#pingPost(User model)";
Helper.logEntrance(getLogger(), signature, new String[]{"model"}, new Object[]{model});
return "unprotected ping post with data";
}
下面是
public abstract class User extends AuditableEntity {
@Indexed
private String name;
private String password;
public User() {
super();
}
public String getName() {
return this.name;
}
public void setName(String value) {
this.name = value;
}
public String getPassword() {
return this.password;
}
public void setPassword(String value) {
this.password = value;
}
}
public abstract class AuditableEntity {
private User createdBy;
private Date createdDate;
public AuditableEntity() {
super();
}
public User getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(User value) {
this.createdBy = value;
}
public Date getCreatedDate() {
return this.createdDate;
}
public void setCreatedDate(Date value) {
this.createdDate = value;
}
}
我已經包含在Maven
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.2</version>
</dependency>
註釋User類,我認爲Spring的配置是否正確。所以我會檢查Json對象是否格式正確。 – 2015-01-09 21:34:47
另外,將MVC記錄下來進行調試,找出錯誤的具體內容和位置。 – chrylis 2015-01-09 22:23:07