public RestResponse(Response response) { Map<String, Object> responseMap = Util.processJsonMap(response.readEntity(String.class)); status = response.getStatus(); message = (String)responseMap.get("message"); extraProperties = (Map) responseMap.get("extraProperties"); children = (List) responseMap.get("children"); Map respProps = (Map) responseMap.get("properties"); if (respProps != null) { this.properties = respProps; } }
public static Map<String, Object> processJsonMap(String json) { Map<String, Object> map; try { map = processJsonObject(new JSONObject(json)); } catch (JSONException e) { map = new HashMap(); } return map; }
public static Map processJsonObject(JSONObject jo) { Map<String, Object> map = new HashMap<String, Object>(); try { Iterator i = jo.keys(); while (i.hasNext()) { String key = (String) i.next(); Object value = jo.get(key); if (value instanceof JSONArray) { map.put(key, processJsonArray((JSONArray) value)); } else if (value instanceof JSONObject) { map.put(key, processJsonObject((JSONObject) value)); } else { map.put(key, value); } } } catch (JSONException e) { LogHelper.log(RestClientLogging.logger, Level.SEVERE, RestClientLogging.REST_CLIENT_JSON_ERROR, e); } return map; }
public static List processJsonArray(JSONArray ja) { List results = new ArrayList(); try { for (int i = 0; i < ja.length(); i++) { Object entry = ja.get(i); if (entry instanceof JSONArray) { results.add(processJsonArray((JSONArray) entry)); } else if (entry instanceof JSONObject) { results.add(processJsonObject((JSONObject) entry)); } else { results.add(entry); } } } catch (JSONException e) { LogHelper.log(RestClientLogging.logger, Level.SEVERE, RestClientLogging.REST_CLIENT_JSON_ERROR, e); } return results; }
protected synchronized void initialize() { if (!initialized) { Response clientResponse = client.target(getRestUrl()).request(RESPONSE_TYPE).get(Response.class); Map<String, Object> responseMap = Util.processJsonMap(clientResponse.readEntity(String.class)); status = clientResponse.getStatus(); getEntityValues(responseMap); getChildren(responseMap); initialized = true; } }