How do I add a type to GWT's Serialization Policy whitelist?

后端 未结 9 630
离开以前
离开以前 2020-11-30 01:30

GWT\'s serializer has limited java.io.Serializable support, but for security reasons there is a whitelist of types it supports. The documentation I\'ve found,

9条回答
  •  臣服心动
    2020-11-30 02:02

    There's a workaround: define a new Dummy class with member fields of all the types that you want to be included in serialization. Then add a method to your RPC interface:

    Dummy dummy(Dummy d);
    

    The implementation is just this:

    Dummy dummy(Dummy d) { return d; }
    

    And the async interface will have this:

    void dummy(Dummy d, AsyncCallback< Dummy> callback);
    

    The GWT compiler will pick this up, and because the Dummy class references those types, it will include them in the white list.

    Example Dummy class:

    public class Dummy implements IsSerializable {
        private java.sql.Date d;
    }
    

提交回复
热议问题