Skip to content

Commit efa7ad8

Browse files
author
Dave Syer
committed
Only use PropertySource.getValue() as a fallback
It converts everything to a String so it isn't helpful to use it as a default. Fixes spring-projectsgh-2891.
1 parent b54960f commit efa7ad8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ private void processEnumerablePropertySource(EnumerablePropertySource<?> source,
121121
.contains(source.getName()) && !includes.matches(propertyName)) {
122122
continue;
123123
}
124-
Object value = source.getProperty(propertyName);
124+
Object value = null;
125125
try {
126-
value = resolver.getProperty(propertyName);
126+
value = resolver.getProperty(propertyName, Object.class);
127127
}
128128
catch (RuntimeException ex) {
129129
// Probably could not resolve placeholders, ignore it here
130+
if (value == null) {
131+
value = source.getProperty(propertyName);
132+
}
130133
}
131134
if (!this.propertyValues.containsKey(propertyName)) {
132135
this.propertyValues.put(propertyName, new PropertyValue(propertyName,

spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public Object getProperty(String name) {
5757
.<String, Object> singletonMap("name", "${foo}")));
5858
}
5959

60+
@Test
61+
public void testTypesPreserved() {
62+
this.propertySources.replace(
63+
"map",
64+
new MapPropertySource("map", Collections.<String, Object> singletonMap(
65+
"name", 123)));
66+
PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(
67+
this.propertySources);
68+
assertEquals(123, propertyValues.getPropertyValues()[0].getValue());
69+
}
70+
6071
@Test
6172
public void testSize() {
6273
PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(

0 commit comments

Comments
 (0)