1
First of all, I agree that the question has gotten a little strange, but I can’t write my question otherwise. At the end of the explanation of the problem if someone wants to suggest a better title that better expresses the problem I will be grateful.
Come on. I got one today map with values as follows:
HashMap<String, Pessoa> map = new HashMap<>();
map.put("max", pessoa1);
map.put("min", pessoa2);
I apply the library Gson and I get the following json:
{
    "min": {
        "name": "Fulano",
        "age": 10,
    },
    "max": {
        "name": "Siclano",
        "age": 13
    }
}
But what I need is: (Look at the square brackets []):
{
    "min": [
        "name": "Fulano",
        "age": 10,
    ],
    "max": [
        "name": "Siclano",
        "age": 13
    ]
}
What I need to do to get the json come with the clasps?
I saw this question on stack. Has relationship with my problem.
The format you need is not a valid JSON format. Vc is consuming some API that requires this format?
– Leonardo Lima
[]are usually used to represent collections. Have you tried aMap<String, List<Pessoa>>,Map<String, Pessoa[]>orMap<String, List<Map<String, Serializable>>>?. Addition example:map.put("max", Collections.singleton(mapaPessoa1). I don’t know exactly how you’re doing the marshalling but one of these options should come close to what you want.– Anthony Accioly
@Anthonyaccioly I’ll try your alternatives
– DNick
Reinforce the @Leonardolima justification. The structure you want does not represent a JSON format. The closest you can get to this is "min": [{"name": "so-and-so", "age": 10}].
– wryel