I want to convert json via jackson library to a map containing camelCase key...say...
from
{
"SomeKey": "SomeValue",
"AnotherKey": "another value",
"InnerJson" : {"TheKey" : "TheValue"}
}
to this...
{
"someKey": "SomeValue",
"anotherKey": "another value",
"innerJson" : {"theKey" : "TheValue"}
}
My Code...
public Map<String, Object> jsonToMap(String jsonString) throws IOException
{
ObjectMapper mapper=new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
return mapper.readValue(jsonString,new TypeReference<Map<String, Object>>(){});
}
But this doesn't work...even other propertyNamingStrategy does not work on json...such as...
{
"someKey": "SomeValue"
}
mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.PascalCaseStrategy())
to
{
"SomeKey": "SomeValue"
}
How to get the camelCase Map key name via jackson... or should I manually loop map and convert key or there are some other way???
Thanks in advance...
The following will transform json with keys on any "case format" to using camelCased keys:
...and a CaseUtil implementation could be something like this:
A unit test: