Author: jafl
Date: Tue Feb  1 01:22:39 2011
New Revision: 1065880

URL: http://svn.apache.org/viewvc?rev=1065880&view=rev
Log:
WW-3498 JSONResult should serialize model, just like JSONInterceptor injects 
into model

Modified:
    
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java
    
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/smd/SMDGenerator.java
    
struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java

Modified: 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java?rev=1065880&r1=1065879&r2=1065880&view=diff
==============================================================================
--- 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java
 (original)
+++ 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java
 Tue Feb  1 01:22:39 2011
@@ -213,7 +213,7 @@ public class JSONResult implements Resul
             ValueStack stack = invocation.getStack();
             rootObject = stack.findValue(root);
         } else {
-            rootObject = invocation.getAction();
+            rootObject = invocation.getStack().peek(); // model overrides 
action
         }
         return rootObject;
     }

Modified: 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/smd/SMDGenerator.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/smd/SMDGenerator.java?rev=1065880&r1=1065879&r2=1065880&view=diff
==============================================================================
--- 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/smd/SMDGenerator.java
 (original)
+++ 
struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/smd/SMDGenerator.java
 Tue Feb  1 01:22:39 2011
@@ -67,7 +67,7 @@ public class SMDGenerator {
             smd.addSMDMethod(smdMethod);
 
             // find params for this method
-            processMethodsParametrs(method, smdMethod);
+            processMethodsParameters(method, smdMethod);
 
         } else {
             if (LOG.isDebugEnabled())
@@ -75,7 +75,7 @@ public class SMDGenerator {
         }
     }
 
-    private void processMethodsParametrs(Method method, 
org.apache.struts2.json.smd.SMDMethod smdMethod) {
+    private void processMethodsParameters(Method method, 
org.apache.struts2.json.smd.SMDMethod smdMethod) {
         int parametersCount = method.getParameterTypes().length;
         if (parametersCount > 0) {
 

Modified: 
struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java?rev=1065880&r1=1065879&r2=1065880&view=diff
==============================================================================
--- 
struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java
 (original)
+++ 
struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java
 Tue Feb  1 01:22:39 2011
@@ -75,6 +75,7 @@ public class JSONResultTest extends Stru
     public void testSMDDisabledSMD() throws Exception {
         JSONResult result = new JSONResult();
         SMDActionTest1 action = new SMDActionTest1();
+        stack.push(action);
 
         this.invocation.setAction(action);
         result.execute(this.invocation);
@@ -90,6 +91,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
         result.setEnableSMD(true);
         SMDActionTest1 action = new SMDActionTest1();
+        stack.push(action);
 
         this.invocation.setAction(action);
         result.execute(this.invocation);
@@ -106,6 +108,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
         result.setEnableSMD(true);
         SMDActionTest2 action = new SMDActionTest2();
+        stack.push(action);
 
         this.invocation.setAction(action);
         result.execute(this.invocation);
@@ -122,6 +125,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
         result.setExcludeNullProperties(true);
         TestAction action = new TestAction();
+        stack.push(action);
         action.setFoo("fool");
 
         this.invocation.setAction(action);
@@ -138,6 +142,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
         result.setWrapPrefix("_prefix_");
         TestAction2 action = new TestAction2();
+        stack.push(action);
 
         this.invocation.setAction(action);
         result.execute(this.invocation);
@@ -153,6 +158,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
         result.setWrapSuffix("_suffix_");
         TestAction2 action = new TestAction2();
+        stack.push(action);
 
         this.invocation.setAction(action);
         result.execute(this.invocation);
@@ -169,6 +175,7 @@ public class JSONResultTest extends Stru
         result.setWrapPrefix("_prefix_");
         result.setWrapSuffix("_suffix_");
         TestAction2 action = new TestAction2();
+        stack.push(action);
 
         this.invocation.setAction(action);
         result.execute(this.invocation);
@@ -185,6 +192,7 @@ public class JSONResultTest extends Stru
         result.setExcludeNullProperties(true);
         result.setPrefix(true);
         TestAction action = new TestAction();
+        stack.push(action);
         action.setFoo("fool");
 
         this.invocation.setAction(action);
@@ -202,6 +210,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
 
         TestAction action = new TestAction();
+        stack.push(action);
 
         // test scape characters
         action.setArray(new String[] { "a", "a", "\"", "\\", "/", "\b", "\f", 
"\n", "\r", "\t" });
@@ -284,6 +293,7 @@ public class JSONResultTest extends Stru
         result.setIgnoreHierarchy(false);
 
         TestAction3 action = new TestAction3();
+        stack.push(action);
         this.invocation.setAction(action);
         result.execute(this.invocation);
 
@@ -299,6 +309,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
 
         TestAction action = new TestAction();
+        stack.push(action);
 
         // test scape characters
         action.setArray(new String[] { "a", "a", "\"", "\\", "/", "\b", "\f", 
"\n", "\r", "\t" });
@@ -376,6 +387,7 @@ public class JSONResultTest extends Stru
 
     private void executeTest2Action(JSONResult result) throws Exception {
         TestAction action = new TestAction();
+        stack.push(action);
 
         // beans
         Bean bean1 = new Bean();
@@ -481,6 +493,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
         result.setIncludeProperties("foo");
         TestAction action = new TestAction();
+        stack.push(action);
         action.setFoo("fooValue");
         action.setBean(new Bean());
         this.invocation.setAction(action);
@@ -497,6 +510,7 @@ public class JSONResultTest extends Stru
         JSONResult result = new JSONResult();
         result.setIncludeProperties("^list\\[\\d+\\]\\.booleanField");
         TestAction action = new TestAction();
+        stack.push(action);
 
         List list = new ArrayList();
 
@@ -530,5 +544,6 @@ public class JSONResultTest extends Stru
         this.context.put(StrutsStatics.SERVLET_CONTEXT, this.servletContext);
         this.invocation = new MockActionInvocation();
         this.invocation.setInvocationContext(this.context);
+        this.invocation.setStack(this.stack);
     }
 }


Reply via email to