Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT: The response could not be deserialized

Tags:

gwt

gwt2

I'm using GWT (2.4) with Spring integrated as in this article. I have problem with getting list of User from database (Hibernate) and populate DataGrid with it. When i call greetingService.allUsers() method, I'm getting error (onFailure()):

com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: The response could not be deserialized

Anybody helps with that? Below some pieces of code. Full working project is here.

  public void onModuleLoad() {
    // ...
    greetingService.allUsers(
        new AsyncCallback<List<User>>(){
            @Override
            public void onFailure(Throwable caught) {
                caught.printStackTrace();
            }
            @Override
            public void onSuccess(List<User> result) {
                GWT.log("SIZE: "+result.size());
                dataGrid.setRowData(result);
            }
        }
    );
    // ...
 }

GreetingServiceImpl

@Override
public List<User> allUsers() {
    return userDAO.findAll();
}

User

@Entity
@Table(name = "users")
public class User implements Serializable, IsSerializable {

    @Id
    private Long id;

    // only Strings and one Date
    private String login;
    private String password;
    private String firstname;
    private String lastname;
    private Date date;
}
like image 563
marioosh Avatar asked Jan 20 '12 14:01

marioosh


People also ask

What is Deserialized object?

Deserialization is the process of reconstructing a data structure or object from a series of bytes or a string in order to instantiate the object for consumption. This is the reverse process of serialization, i.e., converting a data structure or object into a series of bytes for storage or transmission across devices.

What does it mean to serialize and deserialize?

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

What is the meaning of deserialization?

Deserialization is the opposing process which takes data from a file, stream or network and rebuilds it into an object. Serialized objects can be structured in text such as JSON, XML or YAML. Serialization and deserialization are safe, common processes in web applications.

What is deserialization example?

Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object. The byte stream created is platform independent. So, the object serialized on one platform can be deserialized on a different platform.


1 Answers

Documentation for IncompatibleRemoteServiceException says:

This exception can be caused by the following problems:

  • The requested {@link RemoteService} cannot be located via {@link Class#forName(String)} on the server.
  • The requested {@link RemoteService} interface is not implemented by the {@link com.google.gwt.user.server.rpc.RemoteServiceServlet RemoteServiceServlet} instance which is configured to process the request.
  • The requested service method is not defined or inherited by the requested {@link RemoteService} interface.

  • One of the types used in the {@link RemoteService} method invocation has had fields added or removed.
  • The client code receives a type from the server which it cannot
    deserialize.

In your case is the last point, you have a type which cannot be serialized and deserialized, that's a your User class is one of them. You should have one transfer object which implements com.google.gwt.user.client.rpc.IsSerializable interface for transmitting the User object across the network. For further information see: Compatibility with the Java Language and Libraries. GWT RPC method parameters and return types must be transmitted across a network between client and server applications and therefore they must be serializable.

like image 63
Jama A. Avatar answered Sep 28 '22 07:09

Jama A.