【发布时间】:2018-09-02 05:30:11
【问题描述】:
我有一个带有以下代码的restcontroller
@RequestMapping(method = RequestMethod.POST, value = "/student")
public void addTopic(@RequestBody Student student) {
student.setPassword(bCryptPasswordEncoder.encode(student.getPassword()));
studentService.addStudent(student);
}
但如果 json 数据与 Student 对象不匹配,或者格式错误,则会抛出 com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34))。
防止这种情况的最佳做法是什么
【问题讨论】:
-
"防止这种情况的最佳做法是什么" 发送正确的 JSON 格式。
-
对我的 webapp 来说是的,那是真的,但是人们使用其他工具并发送错误数据呢?如果不是正确的 json 格式,我想检查数据并发送和发送响应
标签: json spring rest spring-boot exception