假设我已将 JSON 发布到服务器,如下所示:
{
warFile: {name: "test1", dependencies: [test0, test2]},
param: {build: true, test: true}
}
我有 3 个课程如下:
public class WarFile{
private String name:
private String[] dependencies;
public void setName(){...};
public String getName(){...};
public void setDependencies(){...};
public String[] getDependencies(){...};
}
public class Param{
private boolean build;
private boolean test;
public void setBuild(){...};
public boolean isBuild(){...};
public void setTest(){...};
public boolean isTest(){...};
}
public class Command{
private WarFile warFile;
private Param param;
private void setWarFile(){...};
private WarFile getWarFile(){...};
private void setParam(){...};
private Param getParam(){...};
}
控制器如下:
@RequestMapping(value = "/test.ajax", method = RequestMethod.POST)
public @ResponseBody
BuildResult buildWar(@RequestBody Command cmd) {
return logic.build(cmd.getWarFile(), cmd.getParam());
}
由于warFile
and param
in Command 不是原始类型,我总是收到以下错误:
The request sent by the client was syntactically incorrect.
如果 Command 中的所有属性都是原始类型,我确信没有任何问题。但是这个错误是怎么发生的呢?我的意思是,对象很简单,无需为它们编写自定义反序列化器。