0
votes

Here's the class I'm trying to send:

public class DummyClass implements Serializable, IsSerializable {

  private Map<String, Object> properties = new HashMap<String, Object>();


  public DummyClass() {
    // stuff
  }
  public Object getValue(String key) {
    return properties.getValue(key);
  }
  public void setValue(String key, Object value) {
    properties.put(key, value);
  }
}

But when I try to send it as a parameter to a method in GWT RPC, I get an umbrella exception.

  DummyClass dummy = new DummyClass();
  dummy.setValue("foo", "bar");
  ServiceImpl impl = Gwt.create(SampleService.class).doSomething(dummy);

I could remove the generic types specified in the Map properties... but other than Object or Serializable there's no restriction to what could be stored in the properties map.

Instances of the class serialize just fine using Java's standard serialization.

Also, there's no warnings or errors shown by the GWT compiler.

Is there anything anyone can point out that I can try to get this to work?

1
The basics of Java serialization: Asking Java to serialize the type Object is like giving the bank teller a blank cheque and telling the teller you wish to bank in the cheque. Never encapsulate/embed an indefinite Object within a RPC data transfer object. - Blessed Geek
So then how could I send a Map of String keys to various values (types such as Date, String, Integer)? This serializes just fine using Java serialization... - Cuga

1 Answers

0
votes

Maybe you can try to replace the java.lang.Object return type of getValue() and parameter type of setValue() methods with something more specific (e.g. java.io.Serializable).

Note also you are fine if your object implements only Serializable (no need to implement IsSerializable besides it.).