### Question:
MapJsonAdapter extends JsonAdapter<Map<K, V>> { @Override public Map<K, V> fromJson(JsonReader reader) throws IOException { LinkedHashTreeMap<K, V> result = new LinkedHashTreeMap<>(); reader.beginObject(); while (reader.hasNext()) { reader.promoteNameToValue(); K name = keyAdapter.fromJson(reader); V value = valueAdapter.fromJson(reader); V replaced = result.put(name, value); if (replaced != null) { throw new JsonDataException( "Map key '" + name + "' has multiple values at path " + reader.getPath() + ": " + replaced + " and " + value); } } reader.endObject(); return result; } MapJsonAdapter(Moshi moshi, Type keyType, Type valueType); @Override void toJson(JsonWriter writer, Map<K, V> map); @Override Map<K, V> fromJson(JsonReader reader); @Override String toString(); static final Factory FACTORY; }### Answer:
@Test public void duplicatesAreForbidden() throws Exception { try { fromJson(String.class, Integer.class, "{\"c\":1,\"c\":2}"); fail(); } catch (JsonDataException expected) { assertThat(expected) .hasMessageThat() .isEqualTo("Map key 'c' has multiple values at path $.c: 1 and 2"); } }