我试图使用Spring + Swagger注释通过REST服务更新对象。该方法如下所示:
@ApiOperation(value = "Modifies the entity")
@RequestMapping(value = "/entity", method = RequestMethod.PUT, headers = "Accept=application/json")
@APIMonitor
@ResponseBody
public PubTagger saveEntityDetails(
HttpServletResponse response,
ModelMap model,
@RequestBody final EntityClass entityInfo
)
throws Exception {
...
}实体的定义是:
{
"id": "long",
"description": "string",
"name": "string",
"properties": [
{
"name": "string",
"value": "string"
}
]
}它给了我一个错误
客户端发送的请求在语法上是不正确的()
但只有在填充Properties字段中的对象时才会发生这种情况。如果我把它空着,它就成功了。因此,我推断Spring中嵌套的对象在列表中有问题。
这里有我遗漏的东西吗?我是否必须在模型中指定任何内容才能使其工作?
编辑: Posting实体类
public class Entity {
private Long id;
private String name;
private String description;
private List<Property> properties = new ArrayList<>();
public void setId(final Long id) {
this.id = id;
}
public Entity() {
super();
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public List<Property> getProperties() {
return properties;
}
public void setProperties(List<Property> properties) {
this.properties = properties;
}
}发布于 2014-08-25 19:42:57
谢谢,我发现了错误。
类属性只具有参数化构造函数,没有默认构造函数,因此无法将JSON requestBody配置为对象。
https://stackoverflow.com/questions/25485245
复制相似问题