views:

38

answers:

1

Hello,

I have a simple data structure which is serialized and deserialized. Upon deserialization, I wish that the data structure itself makes a subsequent processing step. In our case, it should simply call String.intern() on all the strings it contains.


Preemptive answers to unrelated questions:

Why don't you simply do this after normally deserializing the object?

  1. This object is serialized/deserialized in a lot of places
  2. This data structure is part of bigger objects which are serialized/deserialized, so you would have to browse any encapsulating object after deserialization as well
  3. Other developpers using the framework might not be aware or forget this step, and would result in a huge bug magnet
  4. It would be ugly

Why do you use String.intern() in the first place?

For performance reasons. We do massive text processing and computation requiring this.


In other words, in:

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;

Is there a way to invoke the default/standard deserialization inside? (So that we can just add our little step afterwards)

Thanks!

Arnaud

+3  A: 

Yes - in.defaultReadObject().

But you'd have to use readObject(..) not readExternal(..)

Note that if you use Externalizable, you are on your own. You can use Serializable and customize partially the output.

Bozho
thanks for the quick answer, i'll try that right now!
arnaud