javaserializationgwtmapdb

GWT - RPC serialization exception and MapDB


I'm using gwt and I'm using mapdb and when I retrieve data as a map (BTreeMap) gwt throw rpc serialization exception. I wrapped the map in an object that implements Serializable and IsSerializable but that don't work.

I don't know why this doesn't work because I read the documentation of mapdb and I use that correctly.

That's the code:

public class WrapperObject implements Serializable, IsSerializable {

          private Map<String, List<String>> map;

          public WrapperObject() {}
          public WrapperObject(Map<String, List<String>> map) {
              this.map = map;
          }
          //GETTERS AND SETTERS
          ...
}


public class Prova {
    ....

    private DB openDB() {
        return DBMaker.shoutdownOnJvmClose().make();
    }

    ...

    public WrapperObject retrieveData() {
        DB db = this.openDB();

        Map<String, List<String>> map = 
        db.getTreeMap("values");

        return new WrapperObject(map);
    }
}

Then in the client class I create a Tree with treeItem using the map.

Thank you for help.


Solution

  • The Problem is, that Map is not Serializable.

    I.e. your WrapperObject is marked as Serializable and IsSerializable, but not all of its Members are marked in that way (see Map and the wrapped List).

    To solve this problem you could change the type of map to an implementation of Map which is serializable (E.g. LinkedHashMap with ArrayList):

    private LinkedHashMap<String, ArrayList<String>> map;