jpyams
jpyams

Reputation: 4364

GWT - Could not get type signature for class

I am working on an application GWT which searches files on different servers. I have my searching code in the server package in a class called Search. To help Search locate the servers, I have the server locations in a class called Login, which is in the shared package. Login contains Authentication objects, which store the information for an individual server.

The code to call Search is as follows:

SearchInterfaceAsync search = GWT.create(SearchInterface.class);
AsyncCallback<Void> callback = new AsyncCallback<Void>() {
    @Override
    public void onFailure(Throwable caught) {
        System.out.println("Error: " + caught.getMessage());
    }
    @Override
    public void onSuccess (Void results) {
        System.out.println("Success!");
    }
};

search.initialize(serverName, login, callback);
search.searchServers(search, variousSearchParameters, callback);

When I run the program and try to search, the program prints Error: could not get type signature for class [Lcom.example.test.shared.Authentication;.

The code for Authentication is as follows:

public class Authentication implements Serializable {

    private static final long serialVersionUID = 5326256122438445301L;

    private String server;
    private String userName;
    private String password;

    public Authentication(String serverName){
        server = serverName;
    }

    public Authentication(String serverName, String user, String pass){
        server = serverName;
        userName = user;
        password = pass;
    }

    public String getServer(){
        return server;
    }

    public String getUserName(){
        return userName;
    }

    public String getPassword() {
        return password;
    }
}

I have tried changing the type declaration, adding Serialization, switching to IsSerializible, and nothing works!

Upvotes: 10

Views: 10941

Answers (3)

Peter L
Peter L

Reputation: 3343

My problem was a missing 'IsSerializable' flag interface on the class named in the error.

Upvotes: 0

Paul Jowett
Paul Jowett

Reputation: 6581

In case it helps others, these are the causes of this error I've run into recently. Sending objects from client to server:

  1. Missing no-args constructor public MyObject() {}
  2. Having a member variable defined as Object (Object can't be serialized)
  3. Forgetting to implement the Serializable interface
  4. Using Generics where type is not determined (I think it was <?> causing issues).
  5. Having the wrong "version" of a "standard" class imported. For example a foreign "List" imported instead of java.util.List.
  6. Having a member variable of type java.io.Serializable. The member variable could transport client-server ok, but sending back failed. Turned out the member was wrapped by a GWT class on the way up that was not serializable ("ServerSerializationStreamReader$BoundedList").
  7. Having a sub-object (member variable) with one of these problems above.

These errors in GWT can show up as simply "500 server errors" which is hard to debug.

Hope that saves some hair-pulling.

Upvotes: 9

Colin Alworth
Colin Alworth

Reputation: 18331

I have tried changing the type declaration, adding Serialization, switching to IsSerializible, and nothing works!

You missed one: you must have a default (zero-arg) constructor, or a new instance can't be created. The deserialization process creates an object then assigns the fields.

I believe you can make this constructor protected so that no developer can accidentally use it.

Upvotes: 13

Related Questions