I want to map the following json to a pojo in Java. In the snippet shown below, result is a Json object, whose value is another json object which is a map. I tried converting this to a Pojo, but it failed. The keys in the result map are dynamic, and I cannot guess them prior.
final_result :
{
"result":
{
"1597696140": 70.32,
"1597696141": 89.12,
"1597696150": 95.32,
}
}
The pojo that I created is :
@JsonIgnoreProperties(ignoreUnknown = true)
public class ResultData {
Map<Long, Double> resultMap;
public ResultData(Map<Long, Double> resultMap) {
this.resultMap = resultMap;
}
public ResultData() {
}
@Override
public String toString() {
return super.toString();
}
}
Upon trying to create the pojo using ObjectMapper :
ObjectMapper objectMapper = new ObjectMapper();
ResultData resultData = objectMapper.readValue(resultData.getJSONObject("result").toString(), ResultData.class);
What am I possible doing wrong here ?
Map<String, String>.Map<Long, Double>and set the resultant map object to the pojo.