use of com.jayway.jsonpath.JsonPathException in project JsonPath by jayway.
the class JsonOrgJsonProvider method getPropertyKeys.
@Override
public Collection<String> getPropertyKeys(Object obj) {
JSONObject jsonObject = toJsonObject(obj);
List<String> keys = new ArrayList<String>();
try {
for (int i = 0; i < jsonObject.names().length(); i++) {
String key = (String) jsonObject.names().get(i);
keys.add(key);
}
return keys;
} catch (JSONException e) {
throw new JsonPathException(e);
}
}
use of com.jayway.jsonpath.JsonPathException in project JsonPath by jayway.
the class JsonOrgJsonProvider method setProperty.
@Override
public void setProperty(Object obj, Object key, Object value) {
try {
if (isMap(obj))
toJsonObject(obj).put(key.toString(), createJsonElement(value));
else {
JSONArray array = toJsonArray(obj);
int index;
if (key != null) {
index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
} else {
index = array.length();
}
if (index == array.length()) {
array.put(createJsonElement(value));
} else {
array.put(index, createJsonElement(value));
}
}
} catch (JSONException e) {
throw new JsonPathException(e);
}
}
Aggregations