我的 SpringBoot 应用程序中有一个 Controller 类。
@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'toole"},它会抛出一个 http 400
"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"JSON parse error: Unexpected end-of-input in VALUE_STRING
知道 jackson 如何将单引号值映射到对象字段吗?
最佳答案
在您的 application.properties
中设置以下属性文件:
spring.jackson.parser.allow-single-quotes=true
关于java - RequestBody JSON 格式有单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49159300/