【发布时间】:2018-03-07 18:55:05
【问题描述】:
我的 SpringBoot 应用中有一个控制器类。
@RestController
@RequestMapping("/{database}/alerts")
public class ControllerB {
@Autowired private ServiceB serviceB;
@Autowired
private B b;
@Autowired
ControllerB(B b,ServiceB serviceB){
this.b = b;
this.serviceB = serviceB;
}
@RequestMapping(method = RequestMethod.POST)
public B dosomethingCrazy(@RequestBody BImpl bimpl) {
String response = serviceB.dosomethingImportant();
return bimpl;
}
}
当 requestBody 的值中有一个单引号时,就会出现问题。例如,如果 requestbody 是 {"name" : "peter o'tool"},它会抛出一个 http 400
"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"JSON 解析错误: Unexpected end-of-input in VALUE_STRING
知道 Jackson 如何将单引号值映射到对象字段吗?
【问题讨论】: