also merge lists

This commit is contained in:
kimchy 2010-11-27 00:05:11 +02:00
parent 577f06fd43
commit 151715dc2f
1 changed files with 9 additions and 0 deletions

View File

@ -20,6 +20,9 @@
package org.elasticsearch.common.xcontent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
@ -40,6 +43,12 @@ public class XContentHelper {
// in the content and in the default, only merge compound ones (maps)
if (content.get(defaultEntry.getKey()) instanceof Map && defaultEntry.getValue() instanceof Map) {
mergeDefaults((Map<String, Object>) content.get(defaultEntry.getKey()), (Map<String, Object>) defaultEntry.getValue());
} else if (content.get(defaultEntry.getKey()) instanceof List && defaultEntry.getValue() instanceof List) {
// if both are lists, simply combine them, first the defaults, then the content
List mergedList = new ArrayList();
mergedList.addAll((Collection) defaultEntry.getValue());
mergedList.addAll((Collection) content.get(defaultEntry.getKey()));
content.put(defaultEntry.getKey(), mergedList);
}
}
}