Werner Heine created TAMAYA-415:
-----------------------------------
Summary: Configuration.getProperties() returns only last part of
the keys when property source is Yaml
Key: TAMAYA-415
URL: https://issues.apache.org/jira/browse/TAMAYA-415
Project: Tamaya
Issue Type: Bug
Components: Core, Extensions
Affects Versions: 0.4-incubating
Reporter: Werner Heine
When using this Yaml file as property source
{code:yaml}
key1: value1
key2:
key2_1: value2_1
key2_2: value2_2
{code}
Configuration.getProperties() returns a map in which the keys only contain the
last part of the Yaml path:
{code:java}
PropertySource ps = ConfigurationFormats.getInstance().createPropertySource(
Thread.currentThread().getContextClassLoader().getResource("myFileConfig.yaml"),
new YAMLFormat());
Configuration cfg = new
DefaultConfigurationBuilder().addPropertySources(ps).build();
cfg.getProperties().forEach((key, value) -> {
if (!key.startsWith("_")) System.out.println(key + " -> " + value);
});
{code}
prints
{noformat}
key1 -> value1
key2_1 -> value2_1
key2_2 -> value2_2
{noformat}
The equivalent code for version 0.3-incubating
{code:java}
PropertySource ps = ConfigurationFormats.createPropertySource(
Thread.currentThread().getContextClassLoader().getResource("myFileConfig.yaml"),
new YAMLFormat());
Configuration cfg = ConfigurationProvider.createConfiguration(
ConfigurationProvider.getConfigurationContextBuilder().addPropertySources(ps).build());
cfg.getProperties().forEach((key, value) -> {
if (!key.startsWith("_")) System.out.println(key + " -> " + value);
});
{code}
returns the full keys (e.g. "key2.key2_1" instead of "key2_1"):
{noformat}
key1 -> value1
key2.key2_2 -> value2_2
key2.key2_1 -> value2_1
{noformat}
Using the full keys to get the values from the configuration works in both
versions:
{code:java}
cfg.get("key2.key2_1")
{code}
returns the correct value in both Tamaya versions.
This issue makes it difficult to iterate over all keys of the configuration,
for example for logging or debugging purposes.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)