Here you can find the source of mergeCompactedValue(Map
static void mergeCompactedValue(Map<String, Object> obj, String key, Object value)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { static void mergeCompactedValue(Map<String, Object> obj, String key, Object value) { if (obj == null) { return; }//from www . j a va 2 s.c o m final Object prop = obj.get(key); if (prop == null) { obj.put(key, value); return; } if (!(prop instanceof List)) { final List<Object> tmp = new ArrayList<Object>(); tmp.add(prop); } if (value instanceof List) { ((List<Object>) prop).addAll((List<Object>) value); } else { ((List<Object>) prop).add(value); } } }