I have a HashMap which is populated from a JSON file. The values in the key-value pair can be of two different types - String or another key-value pair.
For example:
HashMap<String,Object> hashMap = new Map();
The JSON file looks a little something like this:
"custom": {
"mappedReference": {"source": "someMappedReference"},
"somethingElse": "some literal"
}
}
Later on after populating hashMap, when I'm iterating through I need to check if the value is of type HashMap or String. I have tried a number of ways but I can't seem to be able to get the type of the object within the Map.
for(Map.Entry<String,Object> m : hashMap.entrySet())
{
final String key = m.getKey();
final Object value = m.getValue();
if(value instanceof Map<String,String>)
{
//get key and value of the inner key-value pair...
}
else
{
//it's just a string and do what I need with a String.
}
}
Any ideas on how I can get the data type from the Map? Thanks in advance