@SuppressWarnings("unchecked")
    public static void appendValue(Map<String, Object> map, String key, Object value) {
        Object oldValue = map.get(key);
        if (oldValue != null) {
            List<Object> list;
            if (oldValue instanceof List) {
                list = (List<Object>) oldValue;
            } else {
                list = new ArrayList<>();
                list.add(oldValue);
                // replace old entry with list
                map.remove(key);
                map.put(key, list);
            }
            list.add(value);
        } else {
            map.put(key, value);
        }
    }
@Test
    public void testAppendValue() {
        Map<String, Object> map = new HashMap<>();
        CollectionHelper.appendValue(map, "foo", 123);
        assertEquals(1, map.size());

        CollectionHelper.appendValue(map, "foo", 456);
        assertEquals(1, map.size());

        CollectionHelper.appendValue(map, "bar", 789);
        assertEquals(2, map.size());

        List<?> values = (List<?>) map.get("foo");
        assertEquals(2, values.size());
        assertEquals(123, values.get(0));
        assertEquals(456, values.get(1));

        Integer value = (Integer) map.get("bar");
        assertEquals(789, value.intValue());
    }