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);
    jsonArray.put(jsonObject);

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

      

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());
    stringEntity.setContentType("application/json");
    HttpPost post = new HttpPost(
            "http://"server":7474/db/data/ext/serverSideClass/graphdb/processJSONData");
    post.setEntity(stringEntity);
    HTTPPostResponseResults httpResponse = new HTTPPostResponseResults();
    httpResponse.checkResponse(post);

      

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.

 @Name("processJSONData")
 @Description("process the data passed in.")
 @PluginTarget(GraphDatabaseService.class)
 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)",
   "org.neo4j.server.rest.repr.RepresentationFormat.readParameterList(RepresentationFormat.java:97)",
   "org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension

      

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.

+3


source to share





All Articles