简体   繁体   English

Spring MVC @RequestBody中的对象列表产生“语法上不正确的请求”

[英]List of objects in Spring MVC @RequestBody produces “Syntactically incorrect request”

I'm trying to update an object via REST services using Spring MVC + Swagger Annotations. 我正在尝试使用Spring MVC + Swagger注释通过REST服务更新对象。 The method is something like this: 该方法是这样的:

@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 {
         ...
        }

The entity definition is: 实体定义为:

{
  "id": "long",  
  "description": "string",
  "name": "string",
  "properties": [
    {
      "name": "string",
      "value": "string"
    }
  ]
}

It gives me an error 它给我一个错误

The request sent by the client was syntactically incorrect () 客户端发送的请求在语法上不正确()

But it only happens when I fill the objects inside the Properties field. 但这仅在我填充“ Properties字段中的对象时发生。 If I leave it empty it succeeds. 如果我将其留空,它将成功。 So I deduce there's something wrong in Spring MVC with nested objects inside lists. 因此,我推断出在Spring MVC中,列表内部有嵌套对象是有问题的。

Is there anything I'm missing here? 我在这里想念什么吗? Do I have to specify anything in the model to make it work? 我必须在模型中指定任何内容以使其起作用吗?

Edit: Posting Entity class 编辑:发布实体类

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;
    }

}

Thanks, I found the error. 谢谢,我发现了错误。

It was the class Property that only had the Parametrized constructor, without default constructor which made unable to marshall the JSON requestBody into an object. 正是只有Property类的Property类才具有Parametrized构造函数,而没有默认构造函数,这使得无法将JSON requestBody编组为对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 语法要求不正确:spring mvc - request syntactically incorrect: spring mvc Spring MVC-请求在语法上不正确 - Spring MVC - request syntactically incorrect spring mvc - 客户端发送的请求在语法上是不正确的 - spring mvc - The request sent by the client was syntactically incorrect Spring MVC文件上传-客户端发送的请求在语法上不正确 - Spring MVC File Upload - The request sent by the client was syntactically incorrect Spring MVC-上传文件显示客户端发送的请求在语法上不正确 - Spring MVC - upload file shows The request sent by the client was syntactically incorrect 使用Spring MVC进行CRUD时出现错误“客户端发送的请求在语法上不正确” - Error “The request sent by the client was syntactically incorrect” when CRUD with Spring MVC 客户端发送的请求在spring mvc,ajax中在语法上不正确 - The request sent by the client was syntactically incorrect in spring mvc, ajax Spring MVC:上传文件时“客户端发送的请求在语法上不正确”? - Spring MVC : “The request sent by the client was syntactically incorrect” when uploading a file? Spring MVC:错误400客户端发送的请求在语法上是不正确的 - Spring MVC: Error 400 The request sent by the client was syntactically incorrect Spring形式:客户端发送的请求在语法上不正确() - Spring form : The request sent by the client was syntactically incorrect ()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM