empty quey object bug fix
Change-Id: Ie027dc2ed22afd75ee381e162d636643660cf68e
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index 92ac1f3..643eb08 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -22,8 +22,13 @@
*/
public class QuerySerializer {
+ // fixme: not used in any way!
+ @Deprecated
static HashMap<String, Class<? extends AbstractQueryProcessor>> qlProcessorAssignment;
+
+
+
static {
qlProcessorAssignment = new HashMap<String, Class<? extends AbstractQueryProcessor>>();
qlProcessorAssignment
@@ -174,11 +179,10 @@
List warnings = (List) requestMap.get("warnings");
List messages = (List) requestMap.get("messages");
this.collection = mergeCollection(collection, this.collection);
- if (this.collection != null && !this.collection.isEmpty())
- requestMap.put("collection", this.collection);
+ requestMap.put("collection", this.collection);
if (this.meta != null) {
- meta.putAll(this.meta);
- requestMap.put("meta", meta);
+ this.meta.putAll(meta);
+ requestMap.put("meta", this.meta);
}
if (this.errors != null && !this.errors.isEmpty()) {
errors.addAll(this.errors);
@@ -193,11 +197,29 @@
requestMap.put("messages", messages);
}
- return requestMap;
+ return cleanup(requestMap);
}
return new HashMap<>();
}
+ private Map<String, Object> cleanup(Map<String, Object> requestMap) {
+ Iterator<Map.Entry<String, Object>> set = requestMap.entrySet()
+ .iterator();
+ while (set.hasNext()) {
+ Map.Entry<String, Object> entry = set.next();
+ if (entry.getValue() instanceof List && ((List) entry.getValue())
+ .isEmpty())
+ set.remove();
+ else if (entry.getValue() instanceof Map && ((Map) entry.getValue())
+ .isEmpty())
+ set.remove();
+ else if (entry.getValue() instanceof String && ((String) entry
+ .getValue()).isEmpty())
+ set.remove();
+ }
+ return requestMap;
+ }
+
private Map<String, Object> mergeCollection(Map<String, Object> collection1,
Map<String, Object> collection2) {
if (collection1 == null || collection1.isEmpty()) {