Search in sources :

Example 1 with JSONArray

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);
    }
}
Also used : JSONArray(org.neo4j.shell.util.json.JSONArray) JSONException(org.neo4j.shell.util.json.JSONException) JSONObject(org.neo4j.shell.util.json.JSONObject)

Example 2 with JSONArray

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));
    }
}
Also used : JSONArray(org.neo4j.shell.util.json.JSONArray) JSONException(org.neo4j.shell.util.json.JSONException) ShellException(org.neo4j.shell.ShellException)

Example 3 with JSONArray

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);
    }
}
Also used : Attribute(javax.management.Attribute) CompositeData(javax.management.openmbean.CompositeData) JSONArray(org.neo4j.shell.util.json.JSONArray) JSONException(org.neo4j.shell.util.json.JSONException) JSONObject(org.neo4j.shell.util.json.JSONObject)

Aggregations

JSONArray (org.neo4j.shell.util.json.JSONArray)3 JSONException (org.neo4j.shell.util.json.JSONException)3 JSONObject (org.neo4j.shell.util.json.JSONObject)2 Attribute (javax.management.Attribute)1 CompositeData (javax.management.openmbean.CompositeData)1 ShellException (org.neo4j.shell.ShellException)1