'how to map a json when I don't know the names of the parameters and their number in java using rest template?

How to map a json to a class using rest template when I don't know the names of the fruits or their quantities? Because I can have for example only 1 or 150 fruits.

{
    "Apple": 14656,
    "Orange": 4813,
    "Banana": 1722,
    .
    .
    .
}

I tried to map it to this class, but I don't know what name to give it in jsonproperty

public class OpenFruitsDto {

    private final String name;
    private final int amount;

    OpenGitHubRepositoryNameDto(@JsonProperty( ? ) String name, @JsonProperty(?) int amount) {
        this.name = name;
        this.amount = amount;
    }

}


Solution 1:[1]

You can map your object to a JsonNode in case you're not sure about the json structure of your input.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 idanz