Jackson 解析问题

问题描述 投票:0回答:1

在我的 Spring 应用程序中,当我使用邮递员调用它时,我有 Rest api 并发送这个 json

{
    "incomeValue":"Test\\t"
}

它给了

Caused by: com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 9)): has to be escaped using backslash to be included in string value

应用程序部署在tomcat上。 我无法删除

spring spring-boot rest jackson
1个回答
0
投票

我通过 Spring Initializr (https://start.spring.io) 创建了一个 3.2.4 Maven Spring Boot 应用程序,并且仅包含 Spring Web 作为依赖项。

我添加了这个简单的休息控制器:

@RestController
public class DemoRestController {

    @PostMapping("/test")
    public ResponseEntity<Object> test(@RequestBody Test test) {
        return ResponseEntity.ok(test);
    }
}

这个简单的“测试”类...

public class Test {
    private String incomeValue;

    public String getIncomeValue() {
        return incomeValue;
    }

    public void setIncomeValue(String incomeValue) {
        this.incomeValue = incomeValue;
    }
}

然后启动我的网络应用程序(默认情况下使用 Tomcat)并使用您的 json 向端点发送 Post,没有任何问题:

http://localhost:8080/test

HTTP/1.1 200 
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 16 Apr 2024 15:11:56 GMT
Keep-Alive: timeout=60
Connection: keep-alive

{
  "incomeValue": "Test\\t"
}
© www.soinside.com 2019 - 2024. All rights reserved.