Can you use something like this:
http://code.google.com/p/google-gson/
On 2011-08-25 18:18, Taylor Boon wrote:
Hello,
I am working on a web application and would like to send an array of
JSON-serialized objects to my Stripes application as a POST parameter
and have them be serialized into their Java counterparts. The
parameter is received by Stripes as
foos=[{"id":10,"name":"Name 1","description":"Description
1"},{"id":4,"name":"Name 2","description":"Description2"}]
In Java, I have a Foo class. In my ActionBean I have
public List<Foo> foos;
I've also written a FooTypeConverter, which works for a singular
instance of Foo, but I cannot for the life of me figure out how to
handle a list. The DefaultActionBeanPropertyBinder will send the
entire value string to my converter.
Here's what I have tried (in decreasing order of desperation):
-Custom TypeConverterFactory, a JsonTypeConverter to generically
handle JSON, and an annotation to denote fields that should be
processed by the JsonTypeConverter. However, the field is not sent to
the getTypeConverter only the type (List in this case), so I cannot
see whether it has been annotated and hence I never return the
JsonTypeConverter
-Custom ActionBeanPropertyBinder to alter the HTTPRequest's parameter
map, then I remembered that the parameterMap is immutable.
-Changing my FooTypeConverter to handle a JSON array. However, when I
return a List of Foos, bindNonNullValue in the
DefaultActionBeanPropertyBinder fails when trying to set the value
with an EvaluationException ("could not write read-only property")
even though the field is public.
These are just my attempts that I got into testable shape; there were
some other really crazy ideas. J
So, does anyone have any insight into how to do this? Aside from
changing List<Foo> foos to String foos and parsing it post facto in my
ActionBean method. Should I just bite the bullet and write my own
implementation of ActionBeanPropertyBinder and have it check the
parameter for JSON-ness and process it, otherwise defer to the default
property binder? I'm really trying to play by the rules and plug into
the Stripes architecture by doing as little as possible, but this one
really has me stumped.
I hope this makes sense; it's been a long frustrating day. Any insight
would be appreciated.
Best Regards,
Taylor
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management
Up to 160% more powerful than alternatives and 25% more efficient.
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management
Up to 160% more powerful than alternatives and 25% more efficient.
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users