Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4846

Not able to convert Spring object to the JSON response

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.5.12
    • 2.5.14
    • Core Results, Plugin - JSON
    • None

    Description

      Hi,

      I am using latest version of struts struts-2.5.12 and and spring 4.1 as advised. I am having an issue in JSON response. There is an action class which is returning Spring request scoped object as JSON response however I am getting error as below

      ERROR ExceptionMappingInterceptor org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
       org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
      	at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:269)
      	at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:197)
      	at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:182)
      	at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:143)
      	at org.
      

      Any idea what's wrong here ? I am using Java 1.8. I think below code in JSONWriter is not working as expected

      protected Method findBaseAccessor(Class clazz, Method accessor) {
              Method baseAccessor = null;
              if (clazz.getName().contains("$$EnhancerByCGLIB$$")) {
                  try {
                      baseAccessor = Thread.currentThread().getContextClassLoader().loadClass(
                              clazz.getName().substring(0, clazz.getName().indexOf("$$"))).getMethod(
                              accessor.getName(), accessor.getParameterTypes());
                  } catch (Exception ex) {
                      LOG.debug(ex.getMessage(), ex);
                  }
              } else if (clazz.getName().contains("$$_javassist")) {
                  try {
                      baseAccessor = Class.forName(
                              clazz.getName().substring(0, clazz.getName().indexOf("_$$")))
                              .getMethod(accessor.getName(), accessor.getParameterTypes());
                  } catch (Exception ex) {
                      LOG.debug(ex.getMessage(), ex);
                  }
                  
              //in hibernate4.3.7,because javassist3.18.1's class name generate rule is '_$$_jvst'+...
              } else if(clazz.getName().contains("$$_jvst")){
                  try {
                      baseAccessor = Class.forName(
                              clazz.getName().substring(0, clazz.getName().indexOf("_$$")))
                              .getMethod(accessor.getName(), accessor.getParameterTypes());
                  } catch (Exception ex) {
                      LOG.debug(ex.getMessage(), ex);
                  }
              }
              else {
                  return accessor;
              }
              return baseAccessor;
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            vijays2017 Vijay Srivastava
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: