I upgraded Struts from 2.3.7 to 2.3.33 (using Maven). While with version 2.3.7 my web application was working without any issues, after the upgrade to 2.3.33, I receive the following exception when trying to access a web page that contains an Ajax call to the server.
java.lang.NoSuchMethodError: org.apache.struts2.json.JSONWriter.setDateFormatter(Ljava/lang/String;)V at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:106)[struts2-json-plugin-2.3.33.jar:] at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:203)[struts2-json-plugin-2.3.33.jar:] at org.apache.struts2.json.JSONResult.execute(JSONResult.java:177)[struts2-json-plugin-2.3.33.jar:] at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:372)[xwork-core-2.3.33.jar:2.3.33] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:276)[xwork-core-2.3.33.jar:2.3.33] at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)[struts2-core-2.3.33.jar:2.3.33] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)[xwork-core-2.3.33.jar:2.3.33] at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:168)[xwork-core-2.3.33.jar:2.3.33] at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)[xwork-core-2.3.33.jar:2.3.33] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)[xwork-core-2.3.33.jar:2.3.33] at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)[xwork-core-2.3.33.jar:2.3.33] at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)[xwork-core-2.3.33.jar:2.3.33]
The error occurs when my Java Action sends the json response back to the client.
Below is the Ajax call I use:
$.ajax({
url : "list-sample-json",
// data : options.data,
// dataType : "json",
type: "POST",
data: JSON.stringify({ sortParameters : sortParametersList, pageSize:options.data.pageSize, skip:options.data.skip }),
contentType : "application/json; charset=utf-8",
dataType : "json",
success : function (result) {
options.success(result);
},
error : function (response, status, error) {
openErrorDialog(response, status, error);
}
});
My action is accessed without any issues and returns SUCCESS
. As mentioned above, the problem seems to occur when Struts generates the JSON response for the client. Below is also my Java class with json
as a result type.
@Result(name = "success", type = "json", params = { "ignoreHierarchy", "false",
"includeProperties", "textsampleList.*, count" })
@Injectable
public class ListSampleJsonAction {
@Override
public String execute() {
List<SampleDTO> sampleList = new ArrayList<>();
sampleList.add(new SampleDTO("sample")) ;
return SUCCESS;
}
}
I would like to mention that until 2.3.16.3 that the above implementation was working and I was getting a response (with the requested data) from the server.
I use maven 3.0.4 and Java 1.7_079. Can anybody suggest what might have gone wrong?