adapt master to develop
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / webimport / termimport / parser / OntologyTermParser.java
index c9f5fbe56bbcf85f4d9b15ab2668a73e8d61ce54..986093952f37ec5171f8438de4b83b4b657561f0 100644 (file)
@@ -12,9 +12,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
 
@@ -24,19 +25,21 @@ import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrap
  *
  */
 public class OntologyTermParser {
-    public static Collection<OntologyTermWrapper> parse(String response, String terminology){
+    public static Collection<OntologyTermWrapper> parse(String response, String terminology) throws JsonMappingException, JsonProcessingException{
         List<OntologyTermWrapper> wrapperList = new ArrayList<>();
-        try {
-            JSONObject jsonResponse = new JSONObject(response);
-            JSONArray responseArray = ParserUtil.parseResults(jsonResponse);
-            for(int i=0;i<responseArray.length();i++){
-                JSONObject jsonObject = responseArray.getJSONObject(i);
-                String label = ParserUtil.parseLabel(jsonObject);
-                String uriString = ParserUtil.parseUri(jsonObject);
+
+        JsonNode tree = null;
+        ObjectMapper mapper = new ObjectMapper();
+        JsonNode resultNode = null;
+
+        tree =  mapper.readTree(response);
+        if (tree != null) {
+            resultNode =tree.get("results");
+            for (int i = 0; i < resultNode.size(); i++) {
+                String label = ParserUtil.parseLabel(resultNode.get(i));
+                String uriString = ParserUtil.parseUri(resultNode.get(i));
                 wrapperList.add(new OntologyTermWrapper(uriString, label, terminology));
             }
-        } catch (JSONException e) {
-            e.printStackTrace();
         }
         return wrapperList;
     }