This approach will RPC analyze every object in your gwt source path
and take a long time.  We used a similar approach but with clear base
classes (RemoteRequestEvent and RemoteReponseEvent) that can be
extended to demarcate the events that can be RPC'd within our module
(as Serializable is too broad).  Even that approach suffers a bit from
longer compilations but we took the hit for the coding simplicity it
provided.

Sony

On Aug 3, 12:13 pm, Jeffrey Woodward <jeffrey.woodw...@gmail.com>
wrote:
> It seems that the issue of generic Object serialization comes up a lot in
> the arena of GWT-RPC, but good solutions seem to be far more elusive than
> the postings of the problem. The most relevant proposed solution that I
> found came from Scott Blum 
> (http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse...)
> nearly 2 years ago. Before finding this solution, I was faced with the
> problem and as the saying goes, "Necessity is the mother of invention", I
> came up with my own solution that is very different than Scott's. I posted a
> write-up on my solution on the StackOverflow forum 
> (http://stackoverflow.com/questions/2210226/how-can-i-keep-gwt-from-tr...),
> but unfortunately, I haven't received any feedback on it. I also contact
> Scott Blum who suggested that I post my message here (as he hasn't been
> involved with GWT-RPC for some time). I am really looking for some
> confirmation or at least comments or feedback of some sort on my approach,
> so I am hoping that by posting here I can get that; the school of GWT
> thought far exceeds my experience with technology. I won't repeat the entire
> stackoverflow posting here as
> the interested reader can obviously reference it if necessary, but I will
> include my version of a RPC-able generic object which is the core of the
> solution. If would seem that if GWT could provide a standard object of this
> type/functionality, then the masses would...errr might...stop reinventing
> the wheel; I am sure that the developers of GWT can do this better than me;
> however, there may be a significant downside/short-coming of this approach
> that I am overlooking (but at least for now, it is working great in practice
> for me).
>
> All thoughts and comments are appreciated!
>
> -Jeff
>
> public class RpcObject implements IsSerializable {
>     protected HashMap<String, IsSerializable> rpcObjectWrapper = new
> HashMap<String, IsSerializable>();
>
>     /*
>      * NOTE: The following fields are here to
>      * trick/fool/work-around/whatever-you-want-to-call-it GWT-RPC's
>      * serialization policy. Having these types present, even though their
>      * corresponding fields are never used directly, enables GWT-RPC to
>      * serialize/deserialize these primitive types if they are encountered
> in
>      * the rpcWrapperObject! Of course GWT-RPC already knows how to
> serialize
>      * all these primitive types, but since, for example, String doesn't
>      * implement GWT's IsSerializable interface, GWT has no expectation that
> it
>      * should ever be allowed in the rpcWrapperObject instance (and thus
> String,
>      * as well as all the other Java primitives plus Arrays of such types as
>      * well as List, Set, and Map, won't be part of the serialization policy
> of
>      * the RpcObject type). This is unfortunate because thanks to java type
>      * erasure, we can easily stuff Strings, Integers, etc into the wrapper
>      * without any issues; however, GWT-RPC will cowardly refuse to
> serialize
>      * them. Thankfully, it appears that the serialization policy is for the
>      * RpcObject type as a whole rather than for the rpcObjectWrapper field
>      * specifically. So, if we just add some dummy fields with these
> "primitive"
>      * types they will get added to the serialization policy (they are
>      * effectively white-listed) of the type as a whole, and alas, GWT-RPC
> stops
>      * cowardly refusing to serialize them.
>      */
>     protected Byte _byte;
>     protected Short _short;
>     protected Integer _integer;
>     protected Long _long;
>     protected Float _float;
>     protected Double _double;
>     protected Date _date;
>     protected Boolean _boolean;
>
>     protected Byte[] _bytes;
>     protected Short[] _shorts;
>     protected Integer[] _integers;
>     protected Long[] _longs;
>     protected Float[] _floats;
>     protected Double[] _doubles;
>     protected Date[] _dates;
>     protected Boolean[] _booleans;
>
>     protected List<String> _list;
>     protected Set<String> _set;
>     protected Map<String, String> _map;
>
>     public RpcObject() {
>         super();
>     }
>
>     public RpcObject(final Object value) {
>         super();
>         this.setValue(value);
>     }
>
>     @SuppressWarnings("unchecked")
>     public <X> X getValue() {
>         HashMap h = (HashMap) rpcObjectWrapper;
>         X value = (X) h.get("value");
>         return value;
>     }
>
>     @SuppressWarnings("unchecked")
>     public void setValue(Object value) {
>         HashMap h = (HashMap) rpcObjectWrapper;
>         h.put("value", value);
>     }}

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to