Fixed deserialization of wrapped spans

Change-Id: I6a662d576d26ebe1f39336f18438132cfa113eb3
diff --git a/Changes b/Changes
index 2411416..d769cec 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.52 2015-06-27
+0.52 2015-06-30
         - [bugfix] Fixed payload filtering in FocusSpans (margaretha)
 	- [workaround] Reintroduced empty collection support,
 	  as Koral still creates them (diewald)
@@ -19,7 +19,7 @@
 	- [bugfix] JSON-serialization bug in match in case of error messages (diewald)
 	- [bugfix] 'fields' serialization (diewald)
 	- [bugfix] Deserialization of group:disjunction (diewald)
-	- [bugfix] Deserialization of spn/wrap (diewald)
+	- [bugfix] Deserialization of span/wrap (diewald)
 
 0.51 2015-03-17
         - This is a major version (prepared for the GitHub release)
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index fa649ab..72fc389 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -304,7 +304,8 @@
                 if (!json.has("wrap"))
                     return this._termFromJson(json);
 
-                return this._termFromJson(json.get("wrap"));
+                // This is an ugly hack
+                return this._termFromJson(json.get("wrap"), "<>:");
         };
 
         // Unknown query type
@@ -1031,6 +1032,7 @@
 
 
     // Deserialize koral:term
+    // TODO: Not optimal as it does not respect non-term
     private SpanQueryWrapper _termFromJson (JsonNode json, String direction)
             throws QueryException {
         if (!json.has("key") || json.get("key").asText().length() < 1) {
@@ -1048,6 +1050,13 @@
                 : false;
         Boolean isCaseInsensitive = false;
 
+
+        // Ugly direction hack
+        if (direction != null && direction.equals("<>:")) {
+            isTerm = false;
+            direction = null;
+        };
+
         // <legacy>
         if (json.has("caseInsensitive")
                 && json.get("caseInsensitive").asBoolean()) {
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
index 6914dd7..b906609 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
@@ -481,7 +481,7 @@
         SpanQueryWrapper sqwi = jsonQuery(getClass().getResource(
                 "/queries/bugs/unspecified_key_bug.jsonld").getFile());
 
-        assertEquals(sqwi.toQuery().toString(), "spanContain(tokens:s, spanDistance(tokens:s:Erde, tokens:s:Sonne, [(w[0:100], ordered, notExcluded)]))");
+        assertEquals(sqwi.toQuery().toString(), "spanContain(<tokens:s />, spanDistance(tokens:s:Erde, tokens:s:Sonne, [(w[0:100], ordered, notExcluded)]))");
     };