22

What is the purpose of the IsSerializable interface in GWT (regarding the RPC mechanism). I have never been able to find a good explanation as to why it is the way it is and why the default Java Serializable tagging interface does not work.

benstpierre
  • 30,487
  • 46
  • 163
  • 272

2 Answers2

25

Both Serializable and IsSerializable work, according to the GWT serialization docs:

A user-defined class is serializable if all of the following apply:

  1. It is assignable to IsSerializable or Serializable, either because it directly implements one of these interfaces or because it derives from a superclass that does
  2. All non-final, non-transient instance fields are themselves serializable, and
  3. As of GWT 1.5, it must have a default (zero argument) constructor (with any access modifier) or no constructor at all.

One key difference though is that , for security reasons, all Serializable classes must be included in a serialization policy, which is generated at compile time, while IsSerializable classes do not have that requirement.

If your interest is purely in GWT, and you don't e.g. share your model classes between the web application and another application, I suggest you have your model classes/DTOs implement IsSerializable.

Community
  • 1
  • 1
Robert Munteanu
  • 63,405
  • 31
  • 191
  • 270
  • Noob foreign question here. What do you mean by "non-transient instance fields" ? – Jla Jun 18 '10 at 09:24
  • Does the need for a serialization policy have any practical drawbacks, e.g. requiring additional processing time, ...? – Chris Lercher Jun 18 '10 at 21:02
  • 1
    @chris_l I have not measured that, but intuitively it should be faster since the RPC servlet does not have to check the serialisation policy file. Of course, intuition is often wrong when discussing performance. – Robert Munteanu Jun 18 '10 at 21:16
6

If you share your objects with other programs then use Serializable as it is a standard java library function,

But if you only want to pass it between the Server and the client in GWT then use IsSerializable. It helps you make sure that you don't enable to start passing it to places it shouldn't go.

Yon
  • 1,263
  • 1
  • 12
  • 16