Using java.util.ArrayList as the return type in my GWT RPC

862 views
Skip to first unread message

yin...@gmail.com

unread,
Feb 29, 2008, 12:39:32 AM2/29/08
to Google Web Toolkit
Hi,

I have a GWT RPC which has this method:

public interface MessengerService extends RemoteService
{
ArrayList getMsgEvents();

}


But when I compile my GWT code, i get this error:

$ ./MyModule-compile
Computing all possible rebind results for
'com.google.gwt.i18n.client.constants.DateTimeConstants'
Rebinding com.google.gwt.i18n.client.constants.DateTimeConstants
Assimilating generated source
Computing all possible rebind results for
'com.mycompany.client.msg.MessengerService'
Rebinding com.mycompany.client.msg.MessengerService
Invoking <generate-with
class='com.google.gwt.user.rebind.rpc.ServiceInterfaceProxyGenerator'/
>
Generating client proxy for remote service interface
'com.mycompany.client.msg.MessengerService'
Analyzing
'com.mycompany.client.msg.MessengerService' for serializable types
Analyzing methods:
public abstract java.util.ArrayList
getMsgEvents()
Return type: java.util.ArrayList
[WARN] Type 'java.util.ArrayList'
should be parameterized to help the compiler produce the smallest code
size possible for your module. Since the gwt.typeArgs javadoc
annotation is missing, all subtypes of Object will be analyzed for
serializability even if they are not directly or indirectly used
[WARN] Checking all subtypes of
Object which qualify for serialization
Output will be written into ./www/com.mycompany.MyModule
Analyzing permutation #1
[ERROR] Unexpected internal compiler error
java.lang.OutOfMemoryError
[ERROR] Out of memory; to increase the amount of memory, use
the -Xmx flag at startup (java -Xmx128M ...)
[ERROR] Build failed


Can you please tell me how can i fix it?

I am using gwt 1.4.61 on linux.

Thank you.

jkc

unread,
Feb 29, 2008, 3:01:10 AM2/29/08
to Google Web Toolkit
Hi

You will probably need to add the @gwt.typeArgs annotation as
described here
http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.RemoteProcedureCalls.html#SerializableTypes

Hopes this fixes it.



yin...@gmail.com skrev:

k-e-n

unread,
Mar 1, 2008, 5:07:02 PM3/1/08
to Google Web Toolkit
This produces a WARNing, your code will / should still run.
The ERROR might be related to this in someway, but I have just written
some test code & the basic process you describe works fine for me.

Maybe you just need to give the JVM more memory.
I usually just return a regular array [] rather than ArrayList - this
avoids problems of this kind.

-------------------------------------------------------------------------------------------------------------------------------------

More details:


The GWT compiler uses the information in the client interface to help
it decide how to do the serialization.
Since GWT 1.4.6 does not support 'generics' the GWT compiler does not
know what type of objects are in your ArrayList, so it cannot produce
the optimal serialization code.

As jkc mentions the @gwt.typeArgs annotation is supposed to help with
this.

I take a different approach, if I produce an ArrayList on the server
to be sent to the client, I define the method to return a regular
array, and use .toArray() on my ArrayList in the return statement.

So I might have a remote method interface which contains : public
String[] getList();

On the server the implementation is :

public String[] getList()
{
ArrayList<String> list = new ArrayList<String>();

list.add("abc");
list.add("def");

return list.toArray(new String[0]);
}

I hope this help.
Please post something if/when you get this fixed, I would be
interested to know what happens.

Pavel Byles

unread,
Mar 1, 2008, 6:33:24 PM3/1/08
to Google-We...@googlegroups.com
I would also like to know how people handle converting Object to generic type in GWT 1.5 when getting an ArrayList or HashMap via RPC.
I know it's easy to convert a simple list to an array, but what about other generic types like HashMap?

Receiving a HashMap<String, String> via RPC by casting produces the following error:
"The cast from Object to HashMap<String, String> is actually checking against the erased type HashMap."

I assume there must be a way if the HashMap can be wrapped recast and the HashMap extracted, leads me to believe the type information for all types transferred via RPC still exists.

k-e-n

unread,
Mar 23, 2008, 10:46:21 PM3/23/08
to Google Web Toolkit
Perhaps my view is 'old fashioned' but I think if you are trying to
send/receive a complex data structure such as HashMap over a
communications interface, it may be useful to revisit the design/
requirements.
I can see transporting objects, which contain objects, etc, but I
think these objects should be (fixed size) 'data holders' and not have
'behavior'

On Mar 1, 7:33 pm, "Pavel Byles" <pavelby...@gmail.com> wrote:
> I would also like to know how people handle converting Object to generic
> type in *GWT 1.5* when getting an ArrayList or HashMap via RPC.
> I know it's easy to convert a simple list to an array, but what about other
> generic types like HashMap?
>
> Receiving a HashMap<String, String> via RPC by casting produces the
> following error:
> "The cast from Object to HashMap<String, String> is actually checking
> against the erased type HashMap."
>
> I assume there must be a way if the HashMap can be wrapped recast and the
> HashMap extracted, leads me to believe the type information for all types
> transferred via RPC still exists.
>
> On Fri, Feb 29, 2008 at 3:01 AM, jkc <j...@adm.aau.dk> wrote:
>
> > Hi
>
> > You will probably need to add the @gwt.typeArgs annotation as
> > described here
>
> >http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.De...
>
> > Hopes this fixes it.
>
> > ying...@gmail.com skrev:
Reply all
Reply to author
Forward
0 new messages