private List<MessageThread> getFormattedDataMany(Response response) { List<MessageThread> messagethreads = new ArrayList<MessageThread>(); String responseJson = response.readEntity(String.class); System.out.println(responseJson); ObjectMapper mapper = new ObjectMapper(); TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() {}; try { HashMap<String, Object> o = mapper.readValue(responseJson, typeReference); ArrayList<HashMap<String, Object>> list = (ArrayList) ((HashMap) o.get("hits")).get("hits"); for (HashMap<String, Object> map : list) { MessageThread p = MessageThread.parseThread(map); messagethreads.add(p); } } catch (IOException e) { e.printStackTrace(); } return messagethreads; }
private MessageThread getFormattedDataSingle(Response response) { String responseJson = response.readEntity(String.class); System.out.println(responseJson); ObjectMapper mapper = new ObjectMapper(); TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() {}; StringBuilder sb = new StringBuilder(); try { HashMap<String, Object> map = mapper.readValue(responseJson, typeReference); if (Boolean.parseBoolean(map.get("found").toString())) { return MessageThread.parseThread(map); } else { return null; } } catch (Exception e) { return null; } }