Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B68DF200D32 for ; Sun, 5 Nov 2017 17:02:06 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B4CC3160BFF; Sun, 5 Nov 2017 16:02:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D24EC1609EA for ; Sun, 5 Nov 2017 17:02:05 +0100 (CET) Received: (qmail 10053 invoked by uid 500); 5 Nov 2017 16:02:04 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 10043 invoked by uid 99); 5 Nov 2017 16:02:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Nov 2017 16:02:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id F137410AEA3 for ; Sun, 5 Nov 2017 16:02:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 0yBM6uJtR-59 for ; Sun, 5 Nov 2017 16:02:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id C1DA55F30B for ; Sun, 5 Nov 2017 16:02:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4C4B0E0E91 for ; Sun, 5 Nov 2017 16:02:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id D6E372419F for ; Sun, 5 Nov 2017 16:02:00 +0000 (UTC) Date: Sun, 5 Nov 2017 16:02:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@struts.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (WW-4846) Not able to convert Spring object to the JSON response MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 05 Nov 2017 16:02:06 -0000 [ https://issues.apache.org/jira/browse/WW-4846?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16239601#comment-16239601 ] ASF GitHub Bot commented on WW-4846: ------------------------------------ lukaszlenart closed pull request #180: WW-4846 Adds unit tests URL: https://github.com/apache/struts/pull/180 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java b/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java index c5f649333..506210324 100644 --- a/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java +++ b/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java @@ -35,8 +35,11 @@ import javax.servlet.http.HttpServletResponse; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; import org.apache.struts2.StrutsStatics; import org.apache.struts2.StrutsTestCase; +import org.springframework.aop.framework.ProxyFactory; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockServletContext; @@ -153,6 +156,38 @@ public void testExcludeNullPropeties() throws Exception { assertEquals(normalizedExpected, normalizedActual); } + public void testNotTraverseOrIncludeProxyInfo() throws Exception { + JSONResult result = new JSONResult(); + JSONUtil jsonUtil = new JSONUtil(); + JSONWriter writer = new DefaultJSONWriter(); + jsonUtil.setWriter(writer); + result.setJsonUtil(jsonUtil); + Object proxiedAction = new ProxyFactory(new TestAction2()).getProxy(); + stack.push(proxiedAction); + + this.invocation.setAction(proxiedAction); + try { + result.execute(this.invocation); + } catch (Exception ignored) { + } + + String out = response.getContentAsString(); + + String normalizedActual = TestUtils.normalize(out, true); + String normalizedExpected = "{\"name\":\"name\"}"; + assertNotSame(normalizedExpected, normalizedActual); + response.setCommitted(false); + response.reset(); + + writer.setExcludeProxyProperties(true); + result.execute(this.invocation); + + out = response.getContentAsString(); + + normalizedActual = TestUtils.normalize(out, true); + assertEquals(normalizedExpected, normalizedActual); + } + public void testWrapPrefix() throws Exception { JSONResult result = new JSONResult(); result.setWrapPrefix("_prefix_"); ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org > Not able to convert Spring object to the JSON response > ------------------------------------------------------ > > Key: WW-4846 > URL: https://issues.apache.org/jira/browse/WW-4846 > Project: Struts 2 > Issue Type: Bug > Components: Core Results, Plugin - JSON > Affects Versions: 2.5.12 > Reporter: Vijay Srivastava > Priority: Blocker > Fix For: 2.5.14 > > > 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 > {noformat} > 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. > {noformat} > Any idea what's wrong here ? I am using Java 1.8. I think below code in JSONWriter is not working as expected > {code:java} > 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; > } > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)