class marshaling banner

Class Marshaling

This library allows Java objects to be serialized together with their class information. This way they can be de-serialized in an environment where their class information might not be originally present.
My Mug

All source code is released under : Apache License V2
Latest release and changes : WHATSNEW
Installation instructions : INSTALL

If you feel generous, donate and be honored forever : Donate
If you feel like business, sign up a maintenance contract and be privileged : Sign-Up
If you feel cool, buy a t-shirt and make a statement : T-shirt
If you feel like hacking, send me a patch : Submit patch
If you feel nothing like it don't panic, drink water and hangover will soon be over

Using Java Serialization API one can serialize an object into a stream. Using same API one can later on de-serialize the object from the stream.
Upon de-serialization one has to have the class information available to the default classloader.
But what if because of some reason, these classes (or jars) are not present in the environment?
For example, in cluster environment where a distributed computing happens for objects (aka. jobs) implemented by some 3rd party, remote nodes cannot possibly know about their exact implementation classes.
Another situation is when one has to read unknown objects from some media and do not have the original environment available.

In all these cases, the solution would be to store needed class information together with the actual object data. Fortunately Java Serialization API has the means to do that.
This library wraps all this complexity in an easy to use manner. Further on, it has a well defined configuration API which can be used to tailor the solution.

Using the library is rather simple:
    import net.sf.fikin.classmarshaling.MarshaledObject;
    import net.sf.fikin.classmarshaling.util.NullClassSelector;

    MarshaledObject mo = new MarshaledObject( myObj, new NullClassSelector() );

    // now serialize the "mo" instead of myObj
would serialize myObj together with no classes (due to NullClassSelector).
There are several other ClassSelector implementation available in net.sf.fikin.classmarshaling.util package.

De-serialization is equally easy:
    import net.sf.fikin.classmarshaling.MarshaledObject;

    // de-serialize "mo"
    MarshaledObject mo = ...

    // fetch new instance of the actual object
    MyClass myObj = (MyClass) mo.get();

One of the main questions to answer is, which classes have to be serialized together with the object and which can be safely assumed to be present in the environment later on.
  • Typically all JDK classes can be assumed always present.
  • For all other classes would rather hard to come up with generic answer.
    Apparently this decision is for you to make!
    By providing an implementation of ClassSelecor interface.
By serializing class information together with the object itself, we have to acknowledge that this would inevitably:
  • increase a bit the size the resulting stream
  • would slow a bit the serialization process
In many cases though, both disadvantages would be rather insignificant to assert properly.

©2006-2009 Nikolay Fiykov SourceForge