1

I have written a program, where I have to send an ArrayList to Java code through my NodeJS program.
The java program sends back an ArrayList to Nodejs as a response.
I am able to send the ArrayList to Java, and do manipulations.
Sending back the ArrayList from java is also working fine since I have used the System.out.print to verify that.
The problem is in receiving the ArrayList in Nodejs.
Below is the sample code I had written. The NodeJS is printing only "Item_2" twice in the output, whereas it should have printed "Item_1" and then "Item_2".

var confList = java.newInstanceSync("java.util.ArrayList");
confList.addSync("Item_1");
confList.addSync("Item_2");

var dataList = java.newInstanceSync("java.util.ArrayList");

var javaApp = java.newInstanceSync("TestJava");


javaApp.getData(confList, function(err, ret)
{
    if(err) {
        console.log("getData method in Java failed" + err);
    }
    else {
        dataList = ret;
        var data = dataList.getSync(0);
        console.log(data.toStringSync());
        var data = dataList.getSync(1);
        console.log(data.toStringSync());
    }
});

Java code:

public class TestJava
{
    public ArrayList<String> getData(ArrayList<String> conf) throws Exception
    {
        ArrayList<String> list = new ArrayList<String>();
        for(String val: conf)
        {
            val = //some modifications in conf;
            list.add(val);
        }

        return list;
    }
}
mscdex
  • 104,356
  • 15
  • 192
  • 153
aiman
  • 1,049
  • 19
  • 57

0 Answers0