Skip to content
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

null-property property from application.yml is mapped to empty String #8873

Closed
theotherp opened this issue Apr 9, 2017 · 3 comments
Closed
Labels
status: invalid An issue that we don't feel is valid

Comments

@theotherp
Copy link

With Spring Boot 1.5.2.RELEASE I have a String property that is mapped to an application.yml by @ConfigurationProperties. The value in the yml file is null (or ~). But the values are initialized with "" (empty String). According to YAML specification it does allow null values.

The "culprit" is org.springframework.beans.factory.config.YamlProcessor#buildFlattenedMap which executes result.put(key, (value != null ? value : ""))

I've extended the file and configured it to be used and this seems to work fine. But I have to take over a lot of final and private code which makes it a bit brittle. I think Spring should support null values, explicitly remark that their converted to "" or make a change in behavior a bit more comfortable.

Code excerpts:

test:
    setting: ~
@ConfigurationProperties("test")
public class Test {

    String setting;

    public void setSetting(String setting) {
        this.setting = setting; //Will set "setting" to "" instead of null
    }
}

Thanks for your time.

demo.zip

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

@theotherp The code that you have identified is part of Spring Framework rather than Spring Boot. If you'd like to pursue this change, please open a Spring Framework JIRA ticket.

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 10, 2017
@theotherp
Copy link
Author

Oops, sorry. I should've seen that looking at the package name but because it's a problem that affects externalized configuration I thought it would fit here.

Nevertheless I think this should be mentioned in Spring Boot's documentation.

@candrews
Copy link
Contributor

Reported at https://jira.spring.io/browse/SPR-15425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants