Re: Serialization issue with generic Maps

2009-04-16 Thread rmuller

The problem is you cannot use Object as a type argument

Regards,

Ronald
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Serialization issue with generic Maps

2009-04-16 Thread Jason Essington

Object is the super class of EVERY java object, by telling GWT that  
you are returning Object, it would force the compiler to generate a  
serializer for every serializable object on its classpath! that is  
horribly inefficient. you'll want to narrow that type down a bit.

-jason


On Apr 2, 2009, at 8:32 AM, snorbi wrote:


 Hello,

 We have problems serializing generic Maps in gwt-1.6.2 (both in web
 and hosted mode). It seems that type parameters of generic remote
 service method parameters are not scanned properly when searching for
 potential serializable types.

 To reproduce the problem, please see the application snippet below. It
 is a minimal GWT application which calls a remote service from its
 entry method.
 Running the application results in the following exception:

 [ERROR] failure
 com.google.gwt.user.client.rpc.SerializationException:
 gwtsandbox.client.Parameter
   at
 gwtsandbox.client.Service_TypeSerializer.raiseSerializationException
 (Service_TypeSerializer.java:69)
   at gwtsandbox.client.Service_TypeSerializer.serialize(Native Method)
   at
 com 
 .google 
 .gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize
 (ClientSerializationStreamWriter.java:216)
   at
 com 
 .google 
 .gwt 
 .user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject
 (AbstractSerializationStreamWriter.java:129)
   at
 com 
 .google 
 .gwt 
 .user 
 .client.rpc.core.java.util.Map_CustomFieldSerializerBase.serialize
 (Map_CustomFieldSerializerBase.java:50)
   at
 com 
 .google 
 .gwt 
 .user 
 .client.rpc.core.java.util.HashMap_CustomFieldSerializer.serialize
 (HashMap_CustomFieldSerializer.java:36)
   at gwtsandbox.client.Service_TypeSerializer.serialize(Native Method)
   at
 com 
 .google 
 .gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize
 (ClientSerializationStreamWriter.java:216)
   at
 com 
 .google 
 .gwt 
 .user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject
 (AbstractSerializationStreamWriter.java:129)
   at gwtsandbox.client.Service_Proxy.serviceMethod(Service_Proxy.java:
 31)
   at gwtsandbox.client.Application.onModuleLoad(Application.java:20)

 Uncommenting the lines marked with // FIX, it works as expected.

 I think it is a bug, what do you think?

 Thanks for your help!
 Regards:
 Norbi


 Application.gwt.xml
 ---
 module
inherits name='com.google.gwt.user.User' /
entry-point class='gwtsandbox.client.Application' /
source path=client /
 /module

 Application.java
 
 package gwtsandbox.client;

 import java.util.HashMap;
 import java.util.Map;

 import com.google.gwt.core.client.EntryPoint;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.rpc.ServiceDefTarget;

 public class Application implements EntryPoint {
public void onModuleLoad() {
MapString, Object map = new HashMapString, Object();
map.put(key, new Parameter(5));

ServiceAsync serviceProxy = GWT.create(Service.class);
((ServiceDefTarget) serviceProxy).setServiceEntryPoint
 (GWT.getHostPageBaseURL() + gwt/rpc/
+ Service.class.getName());
serviceProxy.serviceMethod(map, new AsyncCallbackVoid() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.toString());
System.out.println(caught);
}

@Override
public void onSuccess(Void result) {
Window.alert(success);
}
});
}
 }

 Parameter.java
 --
 package gwtsandbox.client;

 import java.io.Serializable;

 import com.google.gwt.user.client.rpc.IsSerializable;

 public class Parameter implements Serializable, IsSerializable {
private static final long serialVersionUID = 1L;

private int value;

public Parameter() {
}

public Parameter(int value) {
setValue(value);
}

public int getValue() {
return value;
}

public void setValue(int value) {
this.value = value;
}
 }

 Service.java
 
 package gwtsandbox.client;

 import java.util.Map;

 import com.google.gwt.user.client.rpc.RemoteService;

 public interface Service extends RemoteService {
void serviceMethod(MapString, Object map);

// FIX void serviceMethod(Parameter parameter);
 }

 ServiceAsync.java
 -
 package gwtsandbox.client;

 import java.util.Map;

 import com.google.gwt.user.client.rpc.AsyncCallback;

 public interface ServiceAsync {
void serviceMethod(MapString, Object map, AsyncCallbackVoid
 callback);

// FIX void serviceMethod(Parameter parameter, AsyncCallbackVoid
 callback);
 }

 ServiceServlet.java
 ---
 package gwtsandbox.server;

 import java.util.Map;

 import gwtsandbox.client.Parameter;
 import 

Re: Serialization issue with generic Maps

2009-04-16 Thread Salvador Diaz

Here's a similar thread with possible workarounds:

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/a3081e050d5b719a#

On Apr 2, 4:32 pm, snorbi sandor.norb...@erinors.com wrote:
 Hello,

 We have problems serializing generic Maps in gwt-1.6.2 (both in web
 and hosted mode). It seems that type parameters of generic remote
 service method parameters are not scanned properly when searching for
 potential serializable types.

 To reproduce the problem, please see the application snippet below. It
 is a minimal GWT application which calls a remote service from its
 entry method.
 Running the application results in the following exception:

 [ERROR] failure
 com.google.gwt.user.client.rpc.SerializationException:
 gwtsandbox.client.Parameter
         at
 gwtsandbox.client.Service_TypeSerializer.raiseSerializationException
 (Service_TypeSerializer.java:69)
         at gwtsandbox.client.Service_TypeSerializer.serialize(Native Method)
         at
 com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize
 (ClientSerializationStreamWriter.java:216)
         at
 com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject
 (AbstractSerializationStreamWriter.java:129)
         at
 com.google.gwt.user.client.rpc.core.java.util.Map_CustomFieldSerializerBase.serialize
 (Map_CustomFieldSerializerBase.java:50)
         at
 com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serialize
 (HashMap_CustomFieldSerializer.java:36)
         at gwtsandbox.client.Service_TypeSerializer.serialize(Native Method)
         at
 com.google.gwt.user.client.rpc.impl.ClientSerializationStreamWriter.serialize
 (ClientSerializationStreamWriter.java:216)
         at
 com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject
 (AbstractSerializationStreamWriter.java:129)
         at gwtsandbox.client.Service_Proxy.serviceMethod(Service_Proxy.java:
 31)
         at gwtsandbox.client.Application.onModuleLoad(Application.java:20)

 Uncommenting the lines marked with // FIX, it works as expected.

 I think it is a bug, what do you think?

 Thanks for your help!
 Regards:
 Norbi

 Application.gwt.xml
 ---
 module
     inherits name='com.google.gwt.user.User' /
     entry-point class='gwtsandbox.client.Application' /
     source path=client /
 /module

 Application.java
 
 package gwtsandbox.client;

 import java.util.HashMap;
 import java.util.Map;

 import com.google.gwt.core.client.EntryPoint;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.rpc.ServiceDefTarget;

 public class Application implements EntryPoint {
     public void onModuleLoad() {
         MapString, Object map = new HashMapString, Object();
         map.put(key, new Parameter(5));

         ServiceAsync serviceProxy = GWT.create(Service.class);
         ((ServiceDefTarget) serviceProxy).setServiceEntryPoint
 (GWT.getHostPageBaseURL() + gwt/rpc/
                 + Service.class.getName());
         serviceProxy.serviceMethod(map, new AsyncCallbackVoid() {
             @Override
             public void onFailure(Throwable caught) {
                 Window.alert(caught.toString());
                 System.out.println(caught);
             }

             @Override
             public void onSuccess(Void result) {
                 Window.alert(success);
             }
         });
     }

 }

 Parameter.java
 --
 package gwtsandbox.client;

 import java.io.Serializable;

 import com.google.gwt.user.client.rpc.IsSerializable;

 public class Parameter implements Serializable, IsSerializable {
     private static final long serialVersionUID = 1L;

     private int value;

     public Parameter() {
     }

     public Parameter(int value) {
         setValue(value);
     }

     public int getValue() {
         return value;
     }

     public void setValue(int value) {
         this.value = value;
     }

 }

 Service.java
 
 package gwtsandbox.client;

 import java.util.Map;

 import com.google.gwt.user.client.rpc.RemoteService;

 public interface Service extends RemoteService {
     void serviceMethod(MapString, Object map);

     // FIX void serviceMethod(Parameter parameter);

 }

 ServiceAsync.java
 -
 package gwtsandbox.client;

 import java.util.Map;

 import com.google.gwt.user.client.rpc.AsyncCallback;

 public interface ServiceAsync {
     void serviceMethod(MapString, Object map, AsyncCallbackVoid
 callback);

     // FIX void serviceMethod(Parameter parameter, AsyncCallbackVoid
 callback);

 }

 ServiceServlet.java
 ---
 package gwtsandbox.server;

 import java.util.Map;

 import gwtsandbox.client.Parameter;
 import gwtsandbox.client.Service;

 import com.google.gwt.user.server.rpc.RemoteServiceServlet;

 public class ServiceServlet extends