0
votes
{
    "1580845108000": {
    "alert-signal": 0.0062766625,
    "dog": 0.0130784754,
    "engine": 0.0708726496,
    "human-voice": 0.1199417934,
    "machinery-impact": 0.0472540185,
    "music": 0.021510249,
    "non-machinery-impact": 0.0242645852,
    "powered-saw": 0.0049560028
    },
    "1580845118000": {
    "alert-signal": 0.0111050699,
    "dog": 0.018236123,
    "engine": 0.0586684793,
    "human-voice": 0.139834553,
    "machinery-impact": 0.04508489,
    "music": 0.0201060269,
    "non-machinery-impact": 0.0192962978,
    "powered-saw": 0.0032691984
    },
    "1580845128000": {
    "alert-signal": 0.0074710315,
    "dog": 0.0575219542,
    "engine": 0.0491682142,
    "human-voice": 0.1408204138,
    "machinery-impact": 0.0702125877,
    "music": 0.0147017343,
    "non-machinery-impact": 0.0283612106,
    "powered-saw": 0.0036001888
    }
}

For this JSON response from RestTemplate, How do I construct Java POJO for mapping all fields including key (ie timestamp '1580845128000').

Currently I have ResponseEntity result = restTemplate.exchange(uri, HttpMethod.GET, entity, String.class);

But instead of String.class I want List<> of ReadInstance. How to construct ReadInstance.

-Thanks

1

1 Answers

0
votes

First of all, the posted Json is not a list. A useful feature of Jackson is that it can deserialize any given json to a Map. you can de-serialize the json into a Map and get the map's values():

Map<String, ReadInstance> map = (Map<String, ReadInstance>)mapper.readValue(jsonString, Map.class)