current position:Home>Solution: httpmessagenotreadableexception: JSON parse error: invalid UTF-8

Solution: httpmessagenotreadableexception: JSON parse error: invalid UTF-8

2022-04-29 09:07:12Sun Xiao~

Project scenario :

Project deployment in windows An error occurred on the server HttpMessageNotReadableException: JSON parse error: Invalid UTF-8 start byte

New customers have deployed our project , As a result, when running the debugging interface , stay post The request has Chinese , Will report this error :HttpMessageNotReadableException: JSON parse error: Invalid UTF-8 start byte


Problem description

problem :

Many customers have been using our products before , None of the above problems . When developing locally, I didn't encounter . This mistake can be seen at a glance , It seems to be very simple, that is, the problem of character set . But why are there no other environmental problems .

Cause analysis :

Previous customers , It is used when deploying linux System . The problem this time is windows The server . It is likely that the problem is caused by different character sets .


Solution :

First encounter this kind of error report , The first thing to look at is that the parameter format passed by the front end is that there is a problem with deployment , For example, the common , Extra space , Double quotation marks are Chinese and so on . Because other deployment environments have no problems , Note that there is no problem with the parameter format . This rule out , because Windows The default encoding format in the environment is GBK, So revise Tomcat Runtime encoding format .
stay tomcat bin In the folder catalina.bat Add... To the script
set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8
If it's through “windows service ” start-up
You need to in service.bat Medium JvmOptions Add -Dfile.encoding=UTF-8
If it is jar Package deployment , Just add... In the startup command jvm Parameters can be .
Start command join jvm Parameters java -Dfile.encoding=UTF-8 -jar xxx.jar

Reference resources :https://blog.csdn.net/u011628753/article/details/121624958

So far, the problem has been solved !! I hope I can help you !! come on. !!

copyright notice
author[Sun Xiao~],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290627138281.html

Random recommended