What is the correct way to pass a JSON array to a Neo4j based server class?

I am hitting a wall trying to get the data loaded into a JSON array successfully passed to a java class that goes through a Neo4j server. I intend to pass the list of records from the client side to the server - nothing special here. What I am doing is reading the records on the client side, loading those records into JSON objects, and then putting each JSON object into a JSON array, which must then be passed to the server for further processing.

Here is a section of client code that loads the json object and array. NOTE. only the json related code is removed without using try / catch and other elements in the code.

    JSONArray jsonArray = new JSONArray();
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("field1", field1Value1);
    jsonObject.put("field2", field2Value1);
    jsonObject.put("field3", field3Value1);

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("field1", field1Value2);
    jsonObject.put("field2", field2Value2);
    jsonObject.put("field3", field3Value2);


Here is the client side code that handles the http portion of the equation message - I think that's okay.

    StringEntity stringEntity = new StringEntity(jsonArray.toString());
    HttpPost post = new HttpPost(
    HTTPPostResponseResults httpResponse = new HTTPPostResponseResults();


Here is the method interface to the server-side code, which I consider to be my problem. I think the type of the parameter should be something other than JSONArray, but not sure what.

 @Description("process the data passed in.")
 public String processJSONData(@Source GraphDatabaseService graphDb,
        @Parameter(name = "jsonArray") JSONArray jsonArray) {


And ... this is where the error occurs.

   "message" : "java.util.ArrayList cannot be cast to java.util.Map",
    "exception" : "BadInputException",
   "fullname" : "org.neo4j.server.rest.repr.BadInputException",
   "stacktrace" : [ "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:92)",


The above should cover it for items related to this post. If there is anything you need to clarify please let me know and I will provide it. Thank you in advance.


source to share

All Articles