Skip to content

Add support for UTF-8 and other charset/encoding to @PropertySource [SPR-13874] #18447

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

Closed
spring-projects-issues opened this issue Jan 18, 2016 · 1 comment
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 18, 2016

Fyro opened SPR-13874 and commented

It seems that there is not currently support for encoding/charset in @PropertySource("classpath:/...").

With french characters like "Générales", current result is "Générales" because there is no check with charset/encoding.

Default constructor with default charset, it's ok.

public EncodedResource(Resource resource) {
     this(resource, null, Charset.defaultCharset());
}

Used in ConfigurationClassParser#processPropertySource

	/**
	 * Create a PropertySource having the given name based on Properties
	 * loaded from the given encoded resource.
	 */
	public ResourcePropertySource(String name, Resource resource) throws IOException {
		super(name, PropertiesLoaderUtils.loadProperties(new EncodedResource(resource)));
		this.resourceName = getNameForResource(resource);
	}

	/**
	 * Create a PropertySource based on Properties loaded from the given resource.
	 * The name of the PropertySource will be generated based on the
	 * {@link Resource#getDescription() description} of the given resource.
	 */
	public ResourcePropertySource(Resource resource) throws IOException {
		super(getNameForResource(resource), PropertiesLoaderUtils.loadProperties(new EncodedResource(resource)));
		this.resourceName = null;
	}

Affects: 4.2.4

Issue Links:

Referenced from: commits a3a5a03

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I've added a corresponding encoding attribute to @PropertySource, allowing for a specific encoding to be associated with the given resources.

Juergen

@spring-projects-issues spring-projects-issues added the type: enhancement A general enhancement label Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.3 RC1 milestone Jan 11, 2019
@sbrannen sbrannen changed the title Add support for UTF-8 and other charset/encoding to @PropertySource [SPR-13874] Add support for UTF-8 and other charset/encoding to @PropertySource [SPR-13874] Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants