Extend YAML map key special cases to nested maps

Fixes gh-208
This commit is contained in:
Dave Syer
2014-01-10 15:53:17 +00:00
parent ff3af47ef0
commit cc996ce7f9
2 changed files with 19 additions and 2 deletions

View File

@@ -169,13 +169,17 @@ public class YamlProcessor {
Map<String, Object> result = new LinkedHashMap<String, Object>();
Map<Object, Object> map = (Map<Object, Object>) object;
for (Entry<Object, Object> entry : map.entrySet()) {
Object value = entry.getValue();
if (value instanceof Map) {
value = asMap(value);
}
Object key = entry.getKey();
if (key instanceof CharSequence) {
result.put(key.toString(), entry.getValue());
result.put(key.toString(), value);
}
else {
// It has to be a map key in this case
result.put("[" + key.toString() + "]", entry.getValue());
result.put("[" + key.toString() + "]", value);
}
}
return result;

View File

@@ -76,4 +76,17 @@ public class YamlProcessorTests {
});
}
@Test
public void integerDeepKeyBehaves() {
this.processor.setResources(new Resource[] { new ByteArrayResource(
"foo:\n 1: bar".getBytes()) });
this.processor.process(new MatchCallback() {
@Override
public void process(Properties properties, Map<String, Object> map) {
assertEquals("bar", properties.get("foo[1]"));
assertEquals(1, properties.size());
}
});
}
}