I want to flatten a nested hashmap. For eg,
Map<String, Object> map = new HashMap();
Map<String, Object> map2 = new HashMap();
Map<String, Object> map3 = new HashMap();
map3.put("key3", 123);
map2.put("key2", map3);
map2.put("key4", "test");
map.put("key1", map2);
map.put("key6", "test2");
This will have structure something similar to this:
{
"key1" : {
"key2" : {"key3" : 123 },
"key4" : "test"
},
"key6" : "test2"
}
This should be flattened to a hashmap with structure similar to this:
{
"key1.key2.key3" : 123,
"key1.key4" : "test",
"key6" : "test2"
}
I tried solving this recursively in Java, but not able to produce the right form. Any help is appreciated.