I am trying to deserialize my hashmap(JSON) to POJO class using Jackson - ObjectMapper . Below is the hashmap :
List<Object> setJSONValues = new ArrayList<Object>(Arrays.asList(requestObj));
List<String> setJSONKeys = apiUtility.readJSONKeys(new File("ABC.csv"));
HashMap<String, Object> requestMap = new HashMap<String, Object>();
if (setJSONKeys.size() == setJSONValues.size()) {
for (int i = 0; i < setJSONKeys.size(); i++) {
requestMap.put(setJSONKeys.get(i), setJSONValues.get(i));
}
}
I want to use this requestMap into my POJO class using object mapper see below :
objectMapper.readValue(objectMapper.writeValueAsString(requestMap), MyRequestDTO.class);
I get below error : com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field " "apptDateTime"" (class Collector.MyRequestDTO)
Above error is coming because O/P of my objectMapper.writeValueAsString(requestMap)
is :
{" \"apptDateTime\"":"\"2019-03-19 10:00:00\"","\"meter\"":"\"8682\""
Adding Hashmap O/P :
for (String s:requestMap.keySet())
System.out.println("Key is "+s+"Value is "+requestMap.get(s));
Output : Key is "apptDateTime"Value is "2019-03-19 10:00:00" Key is "meter"Value is "8682"