I want to send JSON array to my java rest metrthod which contains two same bean properties. Here's my Angular $http method
//Some code here
tempJsonData = JSON.stringify(result);
jsonData="{\"employees\":"+tempJsonData+"}";
console.log(jsonData);
//Get the first column first cell value
};
$http({
url: "rest/admin/upload",
method: "POST",
data: jsonData,
headers: {'Content-Type': 'application/json'}
}).success(function(data, status, headers, config) {
if (data) {
$scope.data = data;
//$("#popupmodal1").openModal();
}
}).error(function(data, status, headers, config) {
alert("error");
})
And my Json (var jsonData in angular) Looks like:
{"employees":[{"key1":"value1","key2":"value2"},{"key1":"value3","key2":"value4"}]}
Here's my bean class:
import java.util.ArrayList;
import java.util.List;
public class EmployeeList {
private ArrayList<EmployeeBean> employees;
public ArrayList<EmployeeBean> getEmployees() {
return employees;
}
public void setEmployees(ArrayList<EmployeeBean> employees) {
this.employees = employees;
}
}
This has only one property which is list of EmployeeBean. Here's my REST method:
@POST
@Path("/upload")
@Consumes({ MediaType.APPLICATION_JSON})
@Produces({ "application/json" })
public String upload(EmployeeList employees) {
if(employees!=null){
for(EmployeeBean e:employees.getEmployees())
System.out.println(e.getSignum());
}
else
System.out.println("No data passed");
return "{}";
}
But EmployeeList is not being populated, EmployeeList employees is always Null.
P.S.:
1)I have tried not creating separate class for List and passed List as a parameter to the rest directly, but still not working.
2)I have modified my JSON data from [{"key1":"value1"},{"key1":"value2"}]
to {"employees":[{"key1":"value1"},{"key1":"value2"}]}
Both not working.