在解析JSON请求正文时获得以下异常,
请求正文包含特殊字符"®“(非UTF-8),解析时失败。如何处理请求体中的这个非UTF-8字符?
{
"fields": [
{
"fieldLabel": "data®"
}
]
}
我想用特殊字符保存对象。我试着研究,但找不到一个合适的解决方案。提前谢谢。
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Invalid UTF-8 start byte 0xae; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 start byte 0xae
at [Source: (PushbackInputStream); line: 1, column: 907] (through reference chain: java.util.ArrayList[0]->com.model.TableDefinition["field"]->java.util.ArrayList[1]->com.model.FieldDefinition["fieldLabel"])
发布于 2021-01-05 20:19:32
将"charset=UTF-8“添加到标题中的内容类型解决了此问题:
headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString() + ";charset=UTF-8")
https://stackoverflow.com/questions/62994085
复制相似问题