I am trying to send a JSON Object to Struts2 Action with a Java Class, but the Struts not populating the class. I am using JSON Interceptor to do this.
I don't receive any error, but the property in the class stay null.
My Struts library is:
struts2-core-2.3.24.1 struts2-json-plugin-2.3.24.1 json-lib-2.3-jdk15
Thanks by help!
My struts.xml
<package name="default" namespace="/" extends="json-default">
<interceptors>
<interceptor-stack name="jsonDefaultStack">
<interceptor-ref name="json">
<param name="enableSMD">true</param>
<param name="excludeNullProperties">true</param>
<param name="includeProperties">jsonCustomer</param>
<param name="ignoreSMDMethodInterfaces">false</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="jsonDefaultStack" />
<action name="angularAction" class="actions.CustomerAction" method="findCustomer" >
<result type="json">
<param name="root">jsonCustomer</param>
<param name="excludeNullProperties">true</param>
<param name="noCache">true</param>
</result>
</action>
</package>
My Struts Action
public class CustomerAction extends ActionSupport {
private List<Customer> jsonCustomer;
public List<Customer> getJsonCustomer() {
return jsonCustomer;
}
public void setJsonCustomer(List<Customer> jsonCustomer) {
this.jsonCustomer = jsonCustomer;
}
public String findCustomer() {
List<Customer> js = getJsonCustomer();
return SUCCESS;
}
}
My Java Class
public class Customer {
private String id;
private String name;
private String email;
private String phone;
public Customer() {
}
public Customer(String id, String name, String email, String phone) {
this.id = id;
this.name = name;
this.email = email;
this.phone = phone;
}
//GETTERS AND SETTERS
}
My AngularJS Controller
angular.module('myApp', []);
angular.module('myApp').
controller('MyController', function ($scope, $http) {
$scope.getDataFromServer = function(customer) {
var vjson = {"customer": [{ "id":"4" , "name":"John" , "email":"Doe", "phone":"44444" }]};
$http({
url: 'angularAction',
method: 'POST',
data: angular.toJson(vjson),
headers:{'Content-Type':'application/json'}
}).then (function successCallback(response) {
}, function errorCallback(response) {
})
};
});