Commit cc996ce7 authored by Dave Syer's avatar Dave Syer

Extend YAML map key special cases to nested maps

Fixes gh-208
parent ff3af47e
...@@ -169,13 +169,17 @@ public class YamlProcessor { ...@@ -169,13 +169,17 @@ public class YamlProcessor {
Map<String, Object> result = new LinkedHashMap<String, Object>(); Map<String, Object> result = new LinkedHashMap<String, Object>();
Map<Object, Object> map = (Map<Object, Object>) object; Map<Object, Object> map = (Map<Object, Object>) object;
for (Entry<Object, Object> entry : map.entrySet()) { for (Entry<Object, Object> entry : map.entrySet()) {
Object value = entry.getValue();
if (value instanceof Map) {
value = asMap(value);
}
Object key = entry.getKey(); Object key = entry.getKey();
if (key instanceof CharSequence) { if (key instanceof CharSequence) {
result.put(key.toString(), entry.getValue()); result.put(key.toString(), value);
} }
else { else {
// It has to be a map key in this case // It has to be a map key in this case
result.put("[" + key.toString() + "]", entry.getValue()); result.put("[" + key.toString() + "]", value);
} }
} }
return result; return result;
......
...@@ -76,4 +76,17 @@ public class YamlProcessorTests { ...@@ -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());
}
});
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment