I want to convert json via jackson library to a map containing camelCase key...say...
from
{
\"SomeKey\": \"SomeValue\",
\"Anoth
As you are working with maps/dictionaries instead of binding the JSON data to POJOs (explicit Java classes that match the JSON data), the property naming strategy does not apply:
Class PropertyNamingStrategy ... defines how names of JSON properties ("external names") are derived from names of POJO methods and fields ("internal names")
Therefore, you have to first parse the data using Jackson and then iterate over the result and convert the keys.
Change your code like this:
public Map jsonToMap(String jsonString) throws IOException
{
ObjectMapper mapper=new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
Map map = mapper.readValue(jsonString,new TypeReference
And add these methods:
public String mapKey(String key) {
return Character.toLowerCase(key.charAt(0)) + key.substring(1);
}
public Map convertMap(Map map) {
Map result = new HashMap();
for (Map.Entry entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
result.put(mapKey(key), convertValue(value));
}
return result;
}
public convertList(Lst