use of org.neo4j.shell.util.json.JSONArray in project neo4j by neo4j.
the class AbstractApp method parseArray.
protected static Object[] parseArray(String string) {
try {
JSONArray array = new JSONArray(string);
Object[] result = new Object[array.length()];
for (int i = 0; i < result.length; i++) {
result[i] = array.get(i);
}
return result;
} catch (JSONException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
use of org.neo4j.shell.util.json.JSONArray in project neo4j by neo4j.
the class TransactionProvidingApp method jsonToNeo4jPropertyValue.
private Object jsonToNeo4jPropertyValue(Object value) throws ShellException {
try {
if (value instanceof JSONArray) {
JSONArray array = (JSONArray) value;
Object firstItem = array.get(0);
Object resultArray = Array.newInstance(firstItem.getClass(), array.length());
for (int i = 0; i < array.length(); i++) {
Array.set(resultArray, i, array.get(i));
}
return resultArray;
}
return value;
} catch (JSONException e) {
throw new ShellException(stackTraceAsString(e));
}
}
use of org.neo4j.shell.util.json.JSONArray in project neo4j by neo4j.
the class Dbinfo method printAttribute.
private void printAttribute(JSONObject json, Object value) throws RemoteException, ShellException {
try {
Attribute attribute = (Attribute) value;
Object attributeValue = attribute.getValue();
if (attributeValue != null && attributeValue.getClass().isArray()) {
Object[] arrayValue = (Object[]) attributeValue;
JSONArray array = new JSONArray();
for (Object item : (Object[]) arrayValue) {
if (item instanceof CompositeData) {
array.put(compositeDataAsMap((CompositeData) item));
} else {
array.put(item.toString());
}
}
json.put(attribute.getName(), array);
} else {
json.put(attribute.getName(), attributeValue);
}
} catch (JSONException e) {
throw ShellException.wrapCause(e);
}
}
Aggregations