Fix YamlPropertySourceLoader flatten logic
Fix YamlPropertySourceLoader to correctly flatten keys merged from different documents. Closes gh-2022
This commit is contained in:
parent
ba67e16258
commit
9e394eac22
|
|
@ -78,10 +78,10 @@ public class YamlPropertySourceLoader implements PropertySourceLoader {
|
||||||
process(new MatchCallback() {
|
process(new MatchCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void process(Properties properties, Map<String, Object> map) {
|
public void process(Properties properties, Map<String, Object> map) {
|
||||||
result.putAll(map);
|
result.putAll(getFlattenedMap(map));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return getFlattenedMap(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,4 +62,17 @@ public class YamlPropertySourceLoaderTests {
|
||||||
assertThat(source.getPropertyNames(), equalTo(expected.toArray(new String[] {})));
|
assertThat(source.getPropertyNames(), equalTo(expected.toArray(new String[] {})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergeItems() throws Exception {
|
||||||
|
StringBuilder yaml = new StringBuilder();
|
||||||
|
yaml.append("foo:\n bar: spam\n");
|
||||||
|
yaml.append("---\n");
|
||||||
|
yaml.append("foo:\n baz: wham\n");
|
||||||
|
ByteArrayResource resource = new ByteArrayResource(yaml.toString().getBytes());
|
||||||
|
PropertySource<?> source = this.loader.load("resource", resource, null);
|
||||||
|
assertNotNull(source);
|
||||||
|
assertEquals("spam", source.getProperty("foo.bar"));
|
||||||
|
assertEquals("wham", source.getProperty("foo.baz"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue