我尝试将对象从我的角度服务发送到RestController时遇到异常:
2017-02-26 12:08:46.612 WARN 2766 --- [nio-8080-exec-6] .wsmsDefaultHandlerExceptionResolver:无法读取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException:无法读取文件:N / A. 在[来源:java.io.PushbackInputStream@1e2c3f38; line:1,column:117](通过引用链:com.model.Project [" status"]);嵌套异常是com.fasterxml.jackson.databind.JsonMappingException:N / A. 在[来源:java.io.PushbackInputStream@1e2c3f38; line:1,column:117](通过参考链:com.model.Project [" status"])
我的服务功能:
self.saveProjectToDB = function(project) {
return $http({
method: 'POST',
url: '/project/save',
data: project,
headers: {
'Content-Type':'application/json'
}
});
};
正在发送的对象:
12:20:17.182 Object { id: "58b2af85db91990ace5b1e20", title: "ffs", deadline: null, owner: null, leader: null, status: null, skills: null, resources: Array[3], $$hashKey: "object:26" } 1 resourceCtrl.js:41:4
我的RestController功能:
@RequestMapping(value = "save", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> saveProject(@RequestBody Project project) {
if(project == null) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Body missing!");
}
Project savedProject = projectService.saveProject(project);
return ResponseEntity.status(HttpStatus.CREATED).body(savedProject);
}
我的模特课:
@Document(collection = "project")
public class Project {
@Id
private String id;
private String title;
private String deadline;
private String owner;
private String leader;
private String status;
@DBRef
private List<Skill> skills;
@DBRef(lazy=true)
private List<Resource> resources;
/* Constructor and getters/setters */
我得到的响应状态为400,表明RequestBody项目为空。
修改:
好的,只有当状态!= null时才有效,这很奇怪,因为所有其他变量都允许为空。