Extend YAML map key special cases to nested maps
Fixes gh-208
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user