I'm running into an issue I don't know how to resolve. I need to return a JSON object that has duplicate keys.
I understand this is perfectly valid according to the JSON specification. See ecma-404, page 6 that reads:
The JSON syntax does not impose any restrictions on the strings used as names, does not require that name strings be unique...
I need to return this:
{
"id":"1401",
"sku":"C18-25",
"sku":"A15-70"
}
I've been using a typical rest method in Spring Boot:
@GetMapping("/{id}")
@ResponseBody
public ResponseEntity<?> getProduct(@PathVariable String id) {
Map<String, String> r = new HashMap<>();
r.put("id", "1401");
r.put("sku", "C18-25");
r.put("sku", "A15-70");
return new ResponseEntity<Map<String, String>>(r, HttpStatus.OK);
}
But it only keeps the last entry:
{
"id":"1401",
"sku":"A15-70"
}
How can I return multiple entries with the same name?