You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniel Ruan <da...@gmail.com> on 2011/11/03 16:56:00 UTC

JSON Plugin to Include Parent Action's Properties

Hey,

How do I include some of a parent action's properties in the JSON result of
an action? In the following example, I'd like MyAction2's JSON result
includes name1 and name2 from MyAction1 too.

public abstraction class MyAction1 extends ActionSupport {

    protected String name1;
    protected String name2;

....

}

public class MyAction2 extends MyAction1 {
...}



Thanks!

Daniel

Re: JSON Plugin to Include Parent Action's Properties

Posted by Nelio Souza Santos Filho <ne...@santos-christianini.com>.
It's a property on action definition.
For the example:

		<action name="StatusDocumento" method="list" class="fatura.controller.StatusDocumento">
			<result name="success">statusDocumento/list.jsp</result>
			<result name="json" type="json">
			 	<param name="ignoreHierarchy">false</param>
				<param name="excludeProperties">dao</param>
			</result>
		</action>



Abraços,

Nelio Souza Santos Filho
Solution Engineer

http://about.me/nssantos


Em 03/11/2011, às 13:56, Daniel Ruan escreveu:

> Hey,
> 
> How do I include some of a parent action's properties in the JSON result of
> an action? In the following example, I'd like MyAction2's JSON result
> includes name1 and name2 from MyAction1 too.
> 
> public abstraction class MyAction1 extends ActionSupport {
> 
>    protected String name1;
>    protected String name2;
> 
> ....
> 
> }
> 
> public class MyAction2 extends MyAction1 {
> ...}
> 
> 
> 
> Thanks!
> 
> Daniel


Re: JSON Plugin to Include Parent Action's Properties

Posted by jl...@gmail.com.
There is also a includeProperties that you can use, to select only the properties you want to expose through json.
Sent via BlackBerry from T-Mobile

-----Original Message-----
From: Daniel Ruan <da...@gmail.com>
Date: Thu, 3 Nov 2011 15:59:23 
To: Struts Users Mailing List<us...@struts.apache.org>
Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
Subject: Re: JSON Plugin to Include Parent Action's Properties

Thanks, everybody.

I tried ignoreHierarchy, but got a Java reflection exception. Even if it
worked, it would have include too many things I don't want.  According to
the documentation, it "... serialize properties in all base classes (up to
Object) ".

I could try to use the excludeProperties parameter, but there will be too
many properties to exclude.  In addition, if the super class is modified to
have additional properties, it may break the JSON code without my knowledge.

What I really wish is to be able to selectively include supper class
properties, like syntax like"MyAction1.name1, MyAction2.name2".

Cheers,
Daniel


Re: JSON Plugin to Include Parent Action's Properties

Posted by Chris Pratt <th...@gmail.com>.
Then create an inner class within your Action that contains just the
information youbwant to include in the JSON and set it as the base object
to marshal.
   (*Chris*)
On Nov 3, 2011 12:59 PM, "Daniel Ruan" <da...@gmail.com> wrote:

> Thanks, everybody.
>
> I tried ignoreHierarchy, but got a Java reflection exception. Even if it
> worked, it would have include too many things I don't want.  According to
> the documentation, it "... serialize properties in all base classes (up to
> Object) ".
>
> I could try to use the excludeProperties parameter, but there will be too
> many properties to exclude.  In addition, if the super class is modified to
> have additional properties, it may break the JSON code without my
> knowledge.
>
> What I really wish is to be able to selectively include supper class
> properties, like syntax like"MyAction1.name1, MyAction2.name2".
>
> Cheers,
> Daniel
>

Re: JSON Plugin to Include Parent Action's Properties

Posted by Daniel Ruan <da...@gmail.com>.
Thanks, everybody.

I tried ignoreHierarchy, but got a Java reflection exception. Even if it
worked, it would have include too many things I don't want.  According to
the documentation, it "... serialize properties in all base classes (up to
Object) ".

I could try to use the excludeProperties parameter, but there will be too
many properties to exclude.  In addition, if the super class is modified to
have additional properties, it may break the JSON code without my knowledge.

What I really wish is to be able to selectively include supper class
properties, like syntax like"MyAction1.name1, MyAction2.name2".

Cheers,
Daniel

Re: JSON Plugin to Include Parent Action's Properties

Posted by Maurizio Cucchiara <mc...@apache.org>.
Take a look at http://struts.apache.org/2.2.3/docs/json-plugin.html#JSONPlugin-BaseClasses

Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara



On 3 November 2011 16:56, Daniel Ruan <da...@gmail.com> wrote:
> Hey,
>
> How do I include some of a parent action's properties in the JSON result of
> an action? In the following example, I'd like MyAction2's JSON result
> includes name1 and name2 from MyAction1 too.
>
> public abstraction class MyAction1 extends ActionSupport {
>
>    protected String name1;
>    protected String name2;
>
> ....
>
> }
>
> public class MyAction2 extends MyAction1 {
> ...}
>
>
>
> Thanks!
>
> Daniel
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org