[RFC] Object Serialization

Dejan Lekic dejan.lekic at gmail.com
Sun Mar 18 10:31:32 PDT 2007


These days I am working on object serialization class (and interface) and would like D-brains' comments on following request:

Add a new keyword to D which would enable functionality the "transient" keyword does in JAVA.

I am not a JAVA fan, I have never been, but I just like how elegant JAVA is when it comes to object serialization.

Here is an example how it would "look like":

----------------------------->8------------------------------
class User: Serializable
{
  int id;
  char[] fname;
  char[] sname;
  transient char[] plan;
  // ... methods and constructors here
}

File f = new File("dcommunity.dat", FileMode.Append);
ObjectStream objs = new ObjectStream(f);
User cm = new User(1, "Christopher", "Miller");
objs.writeObject(cm);
objs.flush();
-----------------------------8<------------------------------

The reason behind "transient" keyword is simply to prevent something unimportant from serialization.

After discussion on irc://irc.freenode.org/D IRC channel I have decided to use mixins in order to specify what members are included in serialization - oposite of what "transient" does, because in case of mixin-use it is more clear to specify what should be serialized, than to specify what will not be serialized. :)

I really think adding "transient" keyword would improve D, but I might have overlooked something, that is why I started this thread.

Kind regards

Dejan



More information about the Digitalmars-d mailing list