Skip to content

Provide a configuration option to load properties config data files as UTF-8 #28663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lfz757077613 opened this issue Nov 13, 2021 · 5 comments
Labels
status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Milestone

Comments

@lfz757077613
Copy link

lfz757077613 commented Nov 13, 2021

It works well when I set my properties in application.yml directly
But when I set these properties in additional file imported by "spring.config.import" like below, its charset is wrong
Is there some options to set charset for "spring.config.import"? Otherwise I have to use @PropertySource to set charset, but it do not support yml file
image

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 13, 2021
@wilkinsona
Copy link
Member

What do you mean by wrong? Which charset did you expect to be used and which charset was actually used? Can you provide a minimal sample that reproduces the problem so that we can see exactly what you mean? You can share one with us by zipping it up and attaching it to this issue or by pushing it to a separate repository on GitHub.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Nov 13, 2021
@lfz757077613
Copy link
Author

lfz757077613 commented Nov 13, 2021

What do you mean by wrong? Which charset did you expect to be used and which charset was actually used? Can you provide a minimal sample that reproduces the problem so that we can see exactly what you mean? You can share one with us by zipping it up and attaching it to this issue or by pushing it to a separate repository on GitHub.

you can try this demo project, all of files are utf8.
I have tried to debug to locate the cause, but its a little complex to find where run the decoding code..
If I use @PropertySource(value = {"classpath:other.properties"}, encoding = "UTF-8") instead of "spring.config.import", it works fine

image

springtest.zip

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 13, 2021
@wilkinsona
Copy link
Member

Java's default encoding for properties files is ISO-8859-1 and we deliberately align with this (see #5361 and #10565). As recommended in Properties' javadoc you should use Unicode escapes for non-Latin1 characters. YAML uses UTF-8 by default which is why the value of static-config.right is correct.

We can consider offering a setting to load .properties files using UTF-8 but it will be somewhat difficult to set as it creates something of chicken and egg problem.

@wilkinsona wilkinsona changed the title charset wrong for "spring.config.import" Provide a configuration option to load properties config data files as UTF-8 Nov 13, 2021
@wilkinsona wilkinsona added for: team-meeting An issue we'd like to discuss as a team to make progress type: enhancement A general enhancement and removed status: feedback-provided Feedback has been provided labels Nov 13, 2021
@lfz757077613
Copy link
Author

lfz757077613 commented Nov 13, 2021

Thanks! I understand, this case confused me a long time.
For now, I think "yml" is more convenient than "properties" in springboot project.
Perhaps "spring.config.import" should provide a prefix for encoding such like "optional" prefix.
Thanks again.

@philwebb
Copy link
Member

We'd like to see how the UTF-8 switch planned for Java 18 works out before we do anything in Spring Boot. For now, using YAML seems like the best approach.

@philwebb philwebb added status: pending-design-work Needs design work before any code can be developed and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Nov 24, 2021
@philwebb philwebb added this to the 2.x milestone Nov 24, 2021
@philwebb philwebb modified the milestones: 2.x, 3.x Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants