|
| 1 | +package com.fasterxml.jackson.databind.deser; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 4 | +import com.fasterxml.jackson.databind.BaseMapTest; |
| 5 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 6 | + |
| 7 | +import java.io.IOException; |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.List; |
| 11 | +import java.util.Map; |
| 12 | + |
| 13 | +// tests based on tests in vavr-jackson |
| 14 | +public class TestMixedCollections extends BaseMapTest { |
| 15 | + |
| 16 | + public void testMapOfLists() throws IOException { |
| 17 | + HashMap<Object, Object> src = new HashMap<>(); |
| 18 | + ArrayList<Integer> l1 = new ArrayList<>(); |
| 19 | + l1.add(1); |
| 20 | + l1.add(2); |
| 21 | + ArrayList<Integer> l2 = new ArrayList<>(); |
| 22 | + l2.add(3); |
| 23 | + l2.add(4); |
| 24 | + src.put("key1", l1); |
| 25 | + src.put("key2", l2); |
| 26 | + ObjectMapper mapper = newJsonMapper(); |
| 27 | + String json = mapper.writer().writeValueAsString(src); |
| 28 | + assertEquals(src, mapper.readValue(json, new TypeReference<Map<?, List<?>>>() {})); |
| 29 | + } |
| 30 | + |
| 31 | + public void testMapOfMaps() throws IOException { |
| 32 | + HashMap<Object, Object> src = new HashMap<>(); |
| 33 | + HashMap<Object, Object> innerMap = new HashMap<>(); |
| 34 | + innerMap.put("X", "Y"); |
| 35 | + src.put("1", innerMap); |
| 36 | + ObjectMapper mapper = newJsonMapper(); |
| 37 | + String json = mapper.writer().writeValueAsString(src); |
| 38 | + assertEquals(src, mapper.readValue(json, new TypeReference<Map<?, Map<?, ?>>>() {})); |
| 39 | + } |
| 40 | +} |
0 commit comments