Mohammad Sadegh Rafiei
Mohammad Sadegh Rafiei

Reputation: 516

In GWT I get could not get type signature for class Exception

I define a class with Generic type like below in GWT. when I extend this class with a type or specify a type for this class everything is okay, but at runtime I get "could not get type signature for class Filter" message.

@SuppressWarnings("serial")
public class Filter<T extends Serializable> implements Serializable {
     private FilterInfo<T> info;
     private T value;

     public Filter() { }

     public FilterInfo<T> getInfo() {return info;}
     public void setInfo(FilterInfo<T> info) { this.info = info; }
     public T getValue() { return value; }
     public void setValue(T value) {this.value = value;}
}

I remove below code from above class, then class work correctly.

private FilterInfo<T> info;

but FilterInfo has all prerequisite for use(Serializable, T extends Serializable, default Constructor)

@SuppressWarnings("serial")
public class FilterInfo<T extends Serializable> implements Serializable {
private String name;
private Class<?> type;

public FilterInfo() { }
public FilterInfo(String name, Class<?> type) {
    setName(name);  setType(type.getClass());
}

public String getName() { return name; }
...

Upvotes: 4

Views: 1064

Answers (1)

Colin Alworth
Colin Alworth

Reputation: 18356

Class<?> is not serializable by GWT, therefore neither is FilterInfo, and therefor neither is Filter. Consider that the compiler would need to leave in all possible class literals that are reachable by the compiler, in order to support this.

Instead, either find a different way to describe the type data, or build a CustomFieldSerialize for FilterInfo which can read from the stream and figure out which Class to use as a type, if there is a simple list you support, or an easy way to make a registry.

Upvotes: 2

Related Questions