-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Simon Stratmann opened SPR-15425 and commented
The following issue occured to me while using Spring Boot but is caused by Spring code.
With Spring Boot I have a String property that is mapped to an application.yml
by using @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 the class 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.
Affects: 4.3.7
Attachments:
- demo.zip (5.25 kB)
Issue Links:
- YamlPropertiesFactoryBean loses entries in the YAML document that have an empty array value [SPR-16769] #21310 YamlPropertiesFactoryBean loses entries in the YAML document that have an empty array value
4 votes, 5 watchers