Heterogeneous serializable containers with GWT 1.5 - how to?
3 views
Skip to first unread message
pli...@gmail.com
unread,
Jul 15, 2008, 9:59:35 AM7/15/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
Let say there is a following class:
public class DataRow implements Serializable
{
public <T extends Serializable> void addValue( T o ) {
values.add( o );
}
public <T extends Serializable> T getValue( int idx ) {
return (T)values.get( idx );
}
private List<Serializable> values = new ArrayList<Serializable>();
}
And here is the service:
public interface TestService extends RemoteService {
// Sample interface method of remote interface
DataRow getDataRow();
}
public class TestServiceImpl extends RemoteServiceServlet implements
TestService {
// Implementation of sample interface method
public DataRow getDataRow()
{
DataRow dr = new DataRow();
dr.addValue( "xxx" );
dr.addValue( new Date() );
return dr;
}
}
I'm getting serialization warnings when I call the service from my
code.
It is different every time but it goes somewhat like this:
...
Analyzing the fields of type 'lient.DataRow' that qualify for
serialization
private java.util.List<java.io.Serializable> values
java.util.List<java.io.Serializable>
Checking type argument 0 of type 'java.util.List<E>' because it is
directly exposed in this type or in one of its subtypes
java.io.Serializable
Analyzing subclasses:
java.util.LinkedHashSet<E> <-- THIS IS SOMETIMES DIFFERENT
Checking parameters of 'java.util.LinkedHashSet<E>'
Checking param 'E'
Checking type argument 0 of type 'java.util.LinkedHashSet<E>' because
it is directly exposed in this type or in one of its subtypes
java.lang.Object
In order to produce smaller client-side code, 'Object' is not allowed;
consider using a more specific type
Any suggestions on how to implement heterogeneous serializable
containers?
kozura
unread,
Jul 15, 2008, 10:32:18 AM7/15/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
Make your own parent class, ie MyData implements Serializable, and use
that as the base of all your classes you'd like to send in data. Then
just put the base class in your list, ie List<MyData> values...
If you just use Serializable, GWT has no way to determine all the
possible data types you may be trying to send in your list, and
therefore must assume you can send anything, thus the restriction. By
using your own superclass, you give it a constrained set of possible
types to send.
jk
pli...@gmail.com
unread,
Jul 15, 2008, 1:44:50 PM7/15/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
That would work for custom types but not for Date, String, etc.
Of course you one can suggest to create MyDate, MyString, MyXXX but
this is not a good solution.
I'm actually trying to use custom field serializers now. Seems to be
working just fine.