Reputation: 41
I have a fairly simple case. I have also simplified the names to make it easier to read (see below).
I have an enum and a user-defined class which uses this enum, as well as a String.
According to GWT:
Despite conforming to these rules, an attempt to use these classes results in the following error:
SEVERE: Exception while dispatching incoming RPC call com.google.gwt.user.client.rpc.SerializationException: Type 'com.company.product.Bar was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.company.product.Bar @4c19cc84
Simple case.
GWT bungles it.
Is it broken?
A type is serializable and can be used in a service interface if one of the following is true:
A user-defined class is serializable if all of the following apply:
Foo.java
public enum Foo {
A, B, C;
}
Bar.java
public class Bar implements Serializable {
private static final long serialVersionUID = 604131643709466885L;
private Foo foo;
private String S;
public Bar() {
}
public Foo getFoo() {
return foo;
}
public void setFoo(Foo foo) {
this.foo = foo;
}
public String getS() {
return S;
}
public void setS(String S) {
this.S = S;
}
}
Upvotes: 1
Views: 1481
Reputation: 3832
Is your class available on the client and server side?
The package name 'com.company.product.Bar' indicates, that the class might not be in the right package. Normally you have a package structure like this in GWT:
+- root package
!
+- client
!
+- server
!
+- shared
! !
! +- YourDTO.java
!
+- YourModuleDescriptor.gwt.xml
Your DTO should be located in the shared package.
Upvotes: 1
Reputation: 18356
Type 'com.company.product.Bar was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.
Since you've followed the specific rules it mentioned very clearly, this leaves the other half - something might be wrong with the serialization policy itself. There are two main cases where this can happen - either the policy wasn't present on the server (or is out of date, actually the same thing), or the policy doesn't include that type because it can't be reached by RPC (not on the client sourcepath, explicitly blacklisted, not assignable to one of the expected types - java.lang.Object is cheating).
If the file is outright missing or is out of date, the server will be not send or receive the type it is looking at. If out of date, the client and server have a different idea of what types can go over the wire. Each rpc call contains a reference to the policy file to be used for that call - the client and server need to remain in sync. If on the other hand the object can't be sent because the RPC generator decided that the type wasn't legal to send over the wire, your rpc interface (or referencing type) will need to be changed to properly reference it.
Beyond that, more details will be required - what is your RPC interface, any other log messages on the server, is the *.gwt.rpc
file present on the server?
Upvotes: 0