解析包含复杂数据的Json对象

解析包含复杂数据的Json对象,json,spring,jakarta-ee,jackson,Json,Spring,Jakarta Ee,Jackson,无法分析包含两个简单字段和一个对象的json字符串。我使用杰克逊图书馆。我总是收到400个错误 JSON: 控制器: @RequestMapping(method = RequestMethod.POST) public ResponseEntity<String> createCategory(HttpServletRequest request, @RequestBody Polls polls) { pollsService.add(polls);

无法分析包含两个简单字段和一个对象的json字符串。我使用杰克逊图书馆。我总是收到400个错误

JSON:

控制器:

@RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<String> createCategory(HttpServletRequest request, @RequestBody Polls polls) {


        pollsService.add(polls);

        URI uri = new UriTemplate("{requestUrl}/{username}").expand(request.getRequestURL().toString(), polls.getId());
        final HttpHeaders headers = new HttpHeaders();
        headers.put("Location", Collections.singletonList(uri.toASCIIString()));
        return new ResponseEntity<String>(headers, HttpStatus.CREATED);
    }
包含两个简单字段和一个对象

这不是您在示例代码中发布的内容。可能表示JSON的示例代码实际上不是有效的JSON。它包含两个字符串元素,以及一些非JSON的元素

下面是一个与最初发布的内容类似的有效JSON示例

@RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<String> createCategory(HttpServletRequest request, @RequestBody Polls polls) {


        pollsService.add(polls);

        URI uri = new UriTemplate("{requestUrl}/{username}").expand(request.getRequestURL().toString(), polls.getId());
        final HttpHeaders headers = new HttpHeaders();
        headers.put("Location", Collections.singletonList(uri.toASCIIString()));
        return new ResponseEntity<String>(headers, HttpStatus.CREATED);
    }
{
    "id": "",
    "categories": {"name":"Sport","id":1},
    "name": "sdsd"
}