JSON解析错误:无效的UTF-8中间字节0x6e

时间:2019-07-16 08:08:29

标签: java spring-boot encoding get resttemplate

我正在使用resttemplate从1个端点获取json响应。当我尝试发送请求时,spring抛出异常,它无法将json转换为对象。

我试图通过resttemplate设置编码。

RestTemplate template = new RestTemplate();
        template.getMessageConverters().add(0, new 
StringHttpMessageConverter(Charset.forName("UTF-8")));

我还设置了农产品的编码。

@PostMapping(value="/test/getTest", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)

我还在头上设置了编码。

header.add("Content-Type", "application/json;charset=UTF-8");

仍然出现错误。

我希望回复是200。

编辑: 这是获取请求,因此无需发送没有标题的任何请求。

HttpHeaders header = new HttpHeaders();
    header.add("Content-Type", "application/json;charset=utf-8");

    HttpEntity<Request> entity = new HttpEntity<>(header);

        tempResponse = restTemplate.exchange(url, HttpMethod.GET, entity,
                TestResponse.class);

异常是JSON解析错误:无效的UTF-8中间字节0x6e

0 个答案:

没有答案