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;
*
*/
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;
}