0

I am getting the below error when making an AJAX call in my struts2 application:

 org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException:             org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
 org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:243)
 org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165)
 org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131)
 org.apache.struts2.json.JSONWriter.write(JSONWriter.java:99)
 org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112)
 org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)
 com...hony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
 com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
 org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
 org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
 org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

The correct Action/method are executed when the ajax call is made.

I made all objects referenced in the Action class implement Serializable.

What can i do to fix this problem? I have been searching on the internet .. but no clues..

2 Answers 2

2

The found the problem .. I had BidDecimal objects in my class and JSON serialization is not supported for this type. I converted it to String and double and it iw working now.

1
  • +1 I just ran into this with BigDecimal. I was suspecting they were the problem. Thanks for pointing me in the right direction. Mar 21, 2012 at 19:38
1

solved the error by adding "includeProperties" param to the struts.xml and limiting the variables passed as the response for the AJAX call.

<result name="imgData" type="json">
    <param name="includeProperties"> returnResult </param>
</result>

"returnResult" is the variable containing the data which was passed as the response for the AJAX call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.