use of com.baeldung.jackson.entities.ClassWithAMap in project tutorials by eugenp.
the class JacksonMapDeserializeUnitTest method whenObjectStringMapDeserialize_thenCorrect.
@Test
public void whenObjectStringMapDeserialize_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
final String jsonInput = "{\"Abbott and Costello\":\"Comedy\"}";
TypeReference<HashMap<MyPair, String>> typeRef = new TypeReference<HashMap<MyPair, String>>() {
};
map = mapper.readValue(jsonInput, typeRef);
Assert.assertEquals("Comedy", map.get(new MyPair("Abbott", "Costello")));
ClassWithAMap classWithMap = mapper.readValue(jsonInput, ClassWithAMap.class);
Assert.assertEquals("Comedy", classWithMap.getMap().get(new MyPair("Abbott", "Costello")));
}
Aggregations