The log contains Chinese, which is not displayed correctly.
See original GitHub issueDescription
When print Chinese in Spring Boot projects, then looks like not right, for example:
{"code":45,"name":"广西壮æèªæ²»åº"}
Expected Behavior
Print Chinese normal, like this:
{"code":45,"name":"广西壮族自治区"}
Actual Behavior
{"code":45,"name":"广西壮æèªæ²»åº"}
Possible Fix
Must force set utf-8 encoding
server:
servlet:
encoding:
enabled: true
charset: UTF-8
force: true
The root cause of this problem
The priority order for specifying the response body is:
- explicitly per request using setCharacterEncoding and setContentType
- implicitly per request using setLocale
- per web application via the deployment descriptor or ServletContext.setRequestCharacterEncoding(String)
- container default via vendor specific configuration
- ISO-8859-1
If any possible, get encoding form somewhere else.
Your Environment
- Version used:
org.zalando:logbook-spring-boot-starter:2.3.0
& Spring Boot Ver: 2.3.4.RELEASE
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:15
Top Results From Across the Web
Chinese characters not displaying correctly
You can have this checked by pressing the Windows button + R on your keyboard to open the Run box, then type winver...
Read more >utf 8 - unable to display chinese characters in error_log
I have a php script that pump chinese characters into stdout via error_log. It goes like this: error_log(">>>>>>>>>>article imported: ".
Read more >Chinese characters are not displayed correctly - CodeRanch
However, in the tomcat console, the characters are not displayed properly, instead of chinese characters, ??? are displayed.
Read more >Simplified Chinese characters are not displayed correctly in ...
This started when I checked 'Beta: use Unicode UTF-8 for the support of world langauges' in Change system locale, Country or Region in...
Read more >Doesn't display GB2312 encoded texts correctly for Chinese ...
Now some emails are not displayed correctly. ... sure that charsetalias.properties has no mappings with GB2312 on the right-hand side of the equals...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@whiskeysierra Is it possible to reconsider the fix? As @kyle18th commented, Spring Boot does not provide the (legal) way to set the response charset when the content type is
application/json
.This controller:
produces the UTF-8 JSON response below. It works without setting the response charset.
However, in the Logbook’s log message, the response body is garbled.
This seems to be because Logbook uses the fallback encoding (ISO-8859-1) even if the document is JSON.
Setting the response character encoding explictly:
fixes the log message.
But
APPLICATION_JSON_UTF8_VALUE
is deprecated and should not be used.set the response encoding in the previous filter:
response.setCharacterEncoding(“utf-8”);