gpt4 book ai didi

java - RequestBody JSON 格式有单引号

转载 作者:行者123 更新时间:2023-12-04 17:21:18 24 4
gpt4 key购买 nike

我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com