public static String getJsonForProperties(final Map<String, String> properties) { return getJsonForProperties(new ArrayList<Map<String, String>>() {{ add(properties); }} ); }
public static String getXmlForProperties(final Map<String, String> properties) { return getXmlForProperties(new ArrayList<Map<String, String>>() {{ add(properties); }} ); }
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 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; }
private 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; }
public static List<Map<String, String>> getPropertiesFromJson(String json) { List<Map<String, String>> properties = null; json = json.trim(); if (json.startsWith("{")) { properties = new ArrayList<Map<String, String>>(); properties.add(processJsonMap(json)); } else if (json.startsWith("[")) { try { properties = processJsonArray(new JSONArray(json)); } catch (JSONException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } else { throw new RuntimeException("The JSON string must start with { or ["); // i18n } return properties; }
Map value = processXmlMap(parser); entry.put(key, value); } else if ("list".equals(parser.getLocalName())) { List value = processXmlList(parser); entry.put(key, value); } else {
map = processJsonMap(text); } else if (text.startsWith("<")) { InputStream input = null; case XMLStreamConstants.START_ELEMENT: { if ("map".equals(parser.getLocalName())) { map = processXmlMap(parser);
/**************************************************************************/ private static Map processJsonMap(String json) { Map map; try { map = processJsonObject(new JSONObject(json)); } catch (JSONException e) { map = new HashMap(); } return map; }
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; }
case XMLStreamConstants.START_ELEMENT: { if ("map".equals(parser.getLocalName())) { list.add(processXmlMap(parser)); } else { element = parser.getLocalName();
case XMLStreamConstants.START_ELEMENT: { if ("list".equals(parser.getLocalName())) { list = processXmlList(parser);
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; }
private 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 if (value.getClass().getSimpleName().equalsIgnoreCase("null")) { // The Map may not store null values, but we shouldn't rely on // that behavior, just to be safe map.put(key, null); } else { map.put(key, value); } } } catch (JSONException e) { LogHelper.log(RestClientLogging.logger, Level.SEVERE, RestClientLogging.REST_CLIENT_JSON_ERROR, e); } return map; }
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; } }