Question

Ok, Here is the scenarios.

I have:

CustomerPresenter.java in myproject.client package.

GetCustomer.java in myproject.client package.

GetCustomerResult.java in myproject.client package.

Customer.java in myproject.shared package.

GetCustomerActionHandler.java in myproject.server package.

all these files were automatically generated by eClipse except Customer.java which were created by myself.

CustomerPresenter.java: user can enter customer attributes into textbox & click button then the system should search customers that match the attributes provided.

GetCustomer.java to hold customer attributes such as setCustomerName & getCustomerName, setEmail.. etc

GetCustomerResult.java has setCustomer(customer) & getCustomer(); // customer from shared package

GetCustomerActionHandler.java connect to Db & select name, email... then pass these info into Customer. Ex:

In GetCustomerActionHandler.java

@Override
public GetCustomerResult execute(GetCustomer action, ExecutionContext context)
            throws ActionException {
    String sql="select name, email... from Customer...";
    .....
    String name=dbResults.getString(1);
    Customer c =new Customer();
    c.setName(name);
    GetCustomerResult getCustomerResult=new GetCustomerResult();
    getCustomerResult.setCustomer(c);
    return getCustomerResult;

}

But after ran, i got this err:

Starting Jetty on port 8888
   [WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'myproject.shared.Customer' 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 = myproject.shared.Customer@31e4aa02
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:665)
    at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
......

If we don't put data into object at server level then we have to put it at client level, but it will make the code cumbersome.

Maybe we can make Customer become Serialised or something like that... but i have no idea about that technique.

Why that happened? Do you know how to fix it?

Was it helpful?

Solution

Your Customer class must implement IsSerializable as shown below:

public class Customer implements IsSerializable {
   ...
}

If still it doesn't work then try

public class Customer implements IsSerializable, Serializable {
   ...
}

For more info have a look at What is the purpose of the IsSerializable interface in GWT (regarding the RPC mechanism).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top