简体   繁体   中英

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.

The Problem is, that Map is not Serializable .

Ie 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 (Eg LinkedHashMap with ArrayList ):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM