You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by JOSE L MARTINEZ-AVIAL <jl...@gmail.com> on 2011/02/01 05:19:53 UTC

Re: De-serialize JSON to Action

Hello,
  I was wondering about how to do this, and I just saw your mail. The post
is interesting and useful, but I was wondering if it is possible to
automatice the conversion for beans. According to the documentation(
http://struts.apache.org/2.2.1.1/docs/json-plugin.html) a list of beans will
be mapped to a List of Maps. For example, let's say I receive the following
JSON into my action:

{"identifier":"name",
 "items":[
     {
     "accessLevel":"NO_ACCESS",
     "desc":"Officers",
     "name":"ECO Officer",
     "type":"ROLE"
     },{
     "accessLevel":"NO_ACCESS",
     "desc":"Publications",
     "name":"ECO Publications Manager",
     "type":"ROLE"
     ],
     "targetIdBox":17101}

    As required by the json plugin, I would need to define a
setIdentifier(String), setTargetIdBox(int), and a setItems(List<Map>). That
works correctly, but I would like to automatice the conversion from a Map to
a bean. Is it possible?

    Thanks

Jose Luis

2011/1/31 Harsh C <hc...@gmail.com>

> Looks like this will work for me. Thanks!
>
> On Mon, Jan 31, 2011 at 4:14 PM, Johannes Geppert <jo...@web.de> wrote:
>
> >
> > for a while i wrote a blog post "How to parse a JSON Object when using
> > multiSearch for jqGrid with Java", I think you can adopt it to your
> > problem.
> >
> >
> >
> >
> http://www.jgeppert.com/2010/06/how-to-parse-a-json-object-when-using-multisearch-for-jqgrid-with-java/
> >
> >
> http://www.jgeppert.com/2010/06/how-to-parse-a-json-object-when-using-multisearch-for-jqgrid-with-java/
> >
> > Johannes
> >
> >
> > Harsh C wrote:
> > >
> > > I have been working with the Struts 2 JSON plugin and I have got it set
> > up
> > > so that I can serialize my Java beans as a JSON string and pass it
> along
> > > to
> > > the browser.
> > > Is the reverse possible using the plugin? That is, if I have a JS
> widget
> > > (Dojo, in this case) that spits out JSON, can I read in the JSON string
> > > and
> > > "de-serialize" it to a Java bean?
> > >
> > > I would appreciate it if someone could point me to a best-practice for
> > > doing
> > > so.
> > >
> > > --
> > > *Thanks,
> > > Harsh*
> > >
> > >
> >
> >
> > -----
> > ---
> > web: http://www.jgeppert.com
> > twitter: http://twitter.com/jogep
> >
> > --
> > View this message in context:
> >
> http://old.nabble.com/De-serialize-JSON-to-Action-tp30810552p30810811.html
> > Sent from the Struts - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> *Thanks,
> Harsh*
>

RE: De-serialize JSON to Action

Posted by Jose Luis Martinez Avial <jl...@pb-santander.com>.
Actually, the plugin works just fine. It maps correctly each item to a
bean, so I don't need to user List<Map>, just List<MyBean>, and it works
correctly.

-----Original Message-----
From: Harsh C [mailto:hchaudh1@gmail.com] 
Sent: Monday, January 31, 2011 11:43 PM
To: Struts Users Mailing List
Subject: Re: De-serialize JSON to Action

I would think probably not because at runtime, the JVM would need to
know the type of the objects in the list. But its late here, and I
haven't given it much thought.

On Mon, Jan 31, 2011 at 11:19 PM, JOSE L MARTINEZ-AVIAL
<jl...@gmail.com>wrote:

> Hello,
>  I was wondering about how to do this, and I just saw your mail. The 
> post is interesting and useful, but I was wondering if it is possible 
> to automatice the conversion for beans. According to the 
> documentation(
> http://struts.apache.org/2.2.1.1/docs/json-plugin.html) a list of 
> beans will be mapped to a List of Maps. For example, let's say I 
> receive the following JSON into my action:
>
> {"identifier":"name",
>  "items":[
>     {
>     "accessLevel":"NO_ACCESS",
>     "desc":"Officers",
>     "name":"ECO Officer",
>     "type":"ROLE"
>     },{
>     "accessLevel":"NO_ACCESS",
>     "desc":"Publications",
>     "name":"ECO Publications Manager",
>     "type":"ROLE"
>     ],
>     "targetIdBox":17101}
>
>    As required by the json plugin, I would need to define a 
> setIdentifier(String), setTargetIdBox(int), and a setItems(List<Map>).

> That works correctly, but I would like to automatice the conversion 
> from a Map to a bean. Is it possible?
>
>    Thanks
>
> Jose Luis
>
> 2011/1/31 Harsh C <hc...@gmail.com>
>
> > Looks like this will work for me. Thanks!
> >
> > On Mon, Jan 31, 2011 at 4:14 PM, Johannes Geppert <jo...@web.de>
wrote:
> >
> > >
> > > for a while i wrote a blog post "How to parse a JSON Object when 
> > > using multiSearch for jqGrid with Java", I think you can adopt it 
> > > to your problem.
> > >
> > >
> > >
> > >
> >
> http://www.jgeppert.com/2010/06/how-to-parse-a-json-object-when-using-
> multisearch-for-jqgrid-with-java/
> > >
> > >
> >
> http://www.jgeppert.com/2010/06/how-to-parse-a-json-object-when-using-
> multisearch-for-jqgrid-with-java/
> > >
> > > Johannes
> > >
> > >
> > > Harsh C wrote:
> > > >
> > > > I have been working with the Struts 2 JSON plugin and I have got

> > > > it
> set
> > > up
> > > > so that I can serialize my Java beans as a JSON string and pass 
> > > > it
> > along
> > > > to
> > > > the browser.
> > > > Is the reverse possible using the plugin? That is, if I have a 
> > > > JS
> > widget
> > > > (Dojo, in this case) that spits out JSON, can I read in the JSON
> string
> > > > and
> > > > "de-serialize" it to a Java bean?
> > > >
> > > > I would appreciate it if someone could point me to a 
> > > > best-practice
> for
> > > > doing
> > > > so.
> > > >
> > > > --
> > > > *Thanks,
> > > > Harsh*
> > > >
> > > >
> > >
> > >
> > > -----
> > > ---
> > > web: http://www.jgeppert.com
> > > twitter: http://twitter.com/jogep
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://old.nabble.com/De-serialize-JSON-to-Action-tp30810552p30810811.
> html
> > > Sent from the Struts - User mailing list archive at Nabble.com.
> > >
> > >
> > > ------------------------------------------------------------------
> > > --- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
> >
> > --
> > *Thanks,
> > Harsh*
> >
>



--
*Thanks,
Harsh*

Internet communications are not secure and therefore Banco 
Santander International does not accept legal responsibility for 
the contents of this message. Any views or opinions presented 
are solely those of the author and do not necessarily represent 
those of Banco Santander International unless otherwise 
specifically stated. 

Las comunicaciones v'ia Internet no son seguras y, por lo tanto,
Banco Santander International no asume responsabilidad legal 
ni de ning'un otro tipo por el contenido de este mensaje. 
Cualquier opini'on transmitida pertenece 'unicamente al autor y 
no necesariamente representa la opini'on de Banco Santander 
International, a no ser que est'e expresamente detallado.

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


RE: De-serialize JSON to Action

Posted by Jose Luis Martinez Avial <jl...@pb-santander.com>.
Well, Struts does it in the ParametersInterceptor, so it shouldn't be
difficult to 'map' a map to a bean. I haven't had the time to dig on
that, but maybe someone has and can propose some way to do it.

JL

-----Original Message-----
From: Harsh C [mailto:hchaudh1@gmail.com] 
Sent: Monday, January 31, 2011 11:43 PM
To: Struts Users Mailing List
Subject: Re: De-serialize JSON to Action

I would think probably not because at runtime, the JVM would need to
know the type of the objects in the list. But its late here, and I
haven't given it much thought.

On Mon, Jan 31, 2011 at 11:19 PM, JOSE L MARTINEZ-AVIAL
<jl...@gmail.com>wrote:

> Hello,
>  I was wondering about how to do this, and I just saw your mail. The 
> post is interesting and useful, but I was wondering if it is possible 
> to automatice the conversion for beans. According to the 
> documentation(
> http://struts.apache.org/2.2.1.1/docs/json-plugin.html) a list of 
> beans will be mapped to a List of Maps. For example, let's say I 
> receive the following JSON into my action:
>
> {"identifier":"name",
>  "items":[
>     {
>     "accessLevel":"NO_ACCESS",
>     "desc":"Officers",
>     "name":"ECO Officer",
>     "type":"ROLE"
>     },{
>     "accessLevel":"NO_ACCESS",
>     "desc":"Publications",
>     "name":"ECO Publications Manager",
>     "type":"ROLE"
>     ],
>     "targetIdBox":17101}
>
>    As required by the json plugin, I would need to define a 
> setIdentifier(String), setTargetIdBox(int), and a setItems(List<Map>).

> That works correctly, but I would like to automatice the conversion 
> from a Map to a bean. Is it possible?
>
>    Thanks
>
> Jose Luis
>
> 2011/1/31 Harsh C <hc...@gmail.com>
>
> > Looks like this will work for me. Thanks!
> >
> > On Mon, Jan 31, 2011 at 4:14 PM, Johannes Geppert <jo...@web.de>
wrote:
> >
> > >
> > > for a while i wrote a blog post "How to parse a JSON Object when 
> > > using multiSearch for jqGrid with Java", I think you can adopt it 
> > > to your problem.
> > >
> > >
> > >
> > >
> >
> http://www.jgeppert.com/2010/06/how-to-parse-a-json-object-when-using-
> multisearch-for-jqgrid-with-java/
> > >
> > >
> >
> http://www.jgeppert.com/2010/06/how-to-parse-a-json-object-when-using-
> multisearch-for-jqgrid-with-java/
> > >
> > > Johannes
> > >
> > >
> > > Harsh C wrote:
> > > >
> > > > I have been working with the Struts 2 JSON plugin and I have got

> > > > it
> set
> > > up
> > > > so that I can serialize my Java beans as a JSON string and pass 
> > > > it
> > along
> > > > to
> > > > the browser.
> > > > Is the reverse possible using the plugin? That is, if I have a 
> > > > JS
> > widget
> > > > (Dojo, in this case) that spits out JSON, can I read in the JSON
> string
> > > > and
> > > > "de-serialize" it to a Java bean?
> > > >
> > > > I would appreciate it if someone could point me to a 
> > > > best-practice
> for
> > > > doing
> > > > so.
> > > >
> > > > --
> > > > *Thanks,
> > > > Harsh*
> > > >
> > > >
> > >
> > >
> > > -----
> > > ---
> > > web: http://www.jgeppert.com
> > > twitter: http://twitter.com/jogep
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://old.nabble.com/De-serialize-JSON-to-Action-tp30810552p30810811.
> html
> > > Sent from the Struts - User mailing list archive at Nabble.com.
> > >
> > >
> > > ------------------------------------------------------------------
> > > --- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
> >
> > --
> > *Thanks,
> > Harsh*
> >
>



--
*Thanks,
Harsh*

Internet communications are not secure and therefore Banco 
Santander International does not accept legal responsibility for 
the contents of this message. Any views or opinions presented 
are solely those of the author and do not necessarily represent 
those of Banco Santander International unless otherwise 
specifically stated. 

Las comunicaciones v'ia Internet no son seguras y, por lo tanto,
Banco Santander International no asume responsabilidad legal 
ni de ning'un otro tipo por el contenido de este mensaje. 
Cualquier opini'on transmitida pertenece 'unicamente al autor y 
no necesariamente representa la opini'on de Banco Santander 
International, a no ser que est'e expresamente detallado.

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


Re: De-serialize JSON to Action

Posted by Harsh C <hc...@gmail.com>.
I would think probably not because at runtime, the JVM would need to know
the type of the objects in the list. But its late here, and I haven't given
it much thought.

On Mon, Jan 31, 2011 at 11:19 PM, JOSE L MARTINEZ-AVIAL <jl...@gmail.com>wrote:

> Hello,
>  I was wondering about how to do this, and I just saw your mail. The post
> is interesting and useful, but I was wondering if it is possible to
> automatice the conversion for beans. According to the documentation(
> http://struts.apache.org/2.2.1.1/docs/json-plugin.html) a list of beans
> will
> be mapped to a List of Maps. For example, let's say I receive the following
> JSON into my action:
>
> {"identifier":"name",
>  "items":[
>     {
>     "accessLevel":"NO_ACCESS",
>     "desc":"Officers",
>     "name":"ECO Officer",
>     "type":"ROLE"
>     },{
>     "accessLevel":"NO_ACCESS",
>     "desc":"Publications",
>     "name":"ECO Publications Manager",
>     "type":"ROLE"
>     ],
>     "targetIdBox":17101}
>
>    As required by the json plugin, I would need to define a
> setIdentifier(String), setTargetIdBox(int), and a setItems(List<Map>). That
> works correctly, but I would like to automatice the conversion from a Map
> to
> a bean. Is it possible?
>
>    Thanks
>
> Jose Luis
>
> 2011/1/31 Harsh C <hc...@gmail.com>
>
> > Looks like this will work for me. Thanks!
> >
> > On Mon, Jan 31, 2011 at 4:14 PM, Johannes Geppert <jo...@web.de> wrote:
> >
> > >
> > > for a while i wrote a blog post "How to parse a JSON Object when using
> > > multiSearch for jqGrid with Java", I think you can adopt it to your
> > > problem.
> > >
> > >
> > >
> > >
> >
> http://www.jgeppert.com/2010/06/how-to-parse-a-json-object-when-using-multisearch-for-jqgrid-with-java/
> > >
> > >
> >
> http://www.jgeppert.com/2010/06/how-to-parse-a-json-object-when-using-multisearch-for-jqgrid-with-java/
> > >
> > > Johannes
> > >
> > >
> > > Harsh C wrote:
> > > >
> > > > I have been working with the Struts 2 JSON plugin and I have got it
> set
> > > up
> > > > so that I can serialize my Java beans as a JSON string and pass it
> > along
> > > > to
> > > > the browser.
> > > > Is the reverse possible using the plugin? That is, if I have a JS
> > widget
> > > > (Dojo, in this case) that spits out JSON, can I read in the JSON
> string
> > > > and
> > > > "de-serialize" it to a Java bean?
> > > >
> > > > I would appreciate it if someone could point me to a best-practice
> for
> > > > doing
> > > > so.
> > > >
> > > > --
> > > > *Thanks,
> > > > Harsh*
> > > >
> > > >
> > >
> > >
> > > -----
> > > ---
> > > web: http://www.jgeppert.com
> > > twitter: http://twitter.com/jogep
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://old.nabble.com/De-serialize-JSON-to-Action-tp30810552p30810811.html
> > > Sent from the Struts - User mailing list archive at Nabble.com.
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
> >
> > --
> > *Thanks,
> > Harsh*
> >
>



-- 
*Thanks,
Harsh*