1

Externalizable interface seems to be hard to use. Reasons

  1. Strings in an object can be null. So, I have create and serialize flags to mentioned weather or not to do inReader.readUTF()
  2. For Java Lists its even more hard.

I am not sure, what is the best way to externalize a java HashMap, since I would know at reading time, how many keys are there and if any value is null.

Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121
  • Serialize with Externalizable interface. – Sandeep Jindal Feb 27 '15 at 17:05
  • Why are you using `Externalizable`? Are you working on a legacy application? – Luiggi Mendoza Feb 27 '15 at 17:06
  • The serialization process of a HashMap is talked about in the Java JDK classdocs briefly under [Serialized Forms (HashMap)](http://docs.oracle.com/javase/7/docs/api/serialized-form.html#java.util.HashMap): "*The capacity* of the Hashtable (the length of the bucket array) is emitted (int), followed by *the size* of the Hashtable (the number of key-value mappings), followed by *the key (Object) and value (Object) for each key-value mapping*..". Can't the (Externalization) class responsible for the serialization use the same process? (The size of a HashMap and List is known.) – user2864740 Feb 27 '15 at 17:08
  • Hmm. Good question. There could be many reason for it, but I am using it for a) perfomance, b) Sometimes Hibernate injects its own proxy objects which may error out while deserialization (different Serial ID) – Sandeep Jindal Feb 27 '15 at 17:09
  • Nobody said you have to use read/writeUTF(). You can serialize the strings as Objects, which takes care of the null for you. – user207421 Feb 27 '15 at 20:42

0 Answers0