Most JSON parsers will reject your input file out of control, since duplicate keys at the same level are not allowed (this is the de facto standard). However, some parsers will allow you to handle the duplicate in various ways.
One way to deal with this in Jackson is to map regular attributes to an entity class, and then handle potential duplicates with @JsonAnySetter.
public class Bag {
final transient Multimap<String, Object> multimap = LinkedListMultimap
.create();
@JsonAnySetter
public void add(final String key, final String value) {
multimap.put(key, value);
}
}
Pay attention to the use of multimap: regular hash cards cannot contain duplicate keys, so multi-frame processing is required for a working solution. After deserialization of the input file, all the “regular” JSON attributes will be mapped to the corresponding entity properties, while all duplicates will be saved on the map and available for manual processing.
final List<Object> duplicatedValues = multimap.get(someKey);
, ( , ).