I've a JSON with duplicate keys as shown below.
{
"name": "Test",
"attributes": [{
"attributeName": "One",
"attributeName": "Two",
"attributeName": "Three"
}]
}
When I transform it to a Map<String, Object>
using Jackson, it's transformed as shown below.
{name=Test, attributes=[{attributeName=Three}]}
The value of last occurrence of attribute name is considered. Is there a way to tell Jackson to represent it as a Multimap instead? I am ok to use any implementation of Multimap. My current code is as shown below:
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class TestJSON {
public static void main(String[] args) throws Exception{
ObjectMapper mapper = new ObjectMapper();
String json = "{\"name\": \"Test\",\"attributes\": [{\"attributeName\": \"One\",\"attributeName\": \"Two\",\"attributeName\": \"Three\"}]}";
Map<String, Object> map = new HashMap<>();
map = mapper.readValue(json, new TypeReference<Map<String, Object>>(){});
System.out.println(map);
}
}