Learn to serialize HashMap using Google Gson library. Also learn to deserialize JSON string to HashMap containing custom Objects using Gson such that field values are copied into appropriate generic types. These conversion can be used to create deep clone of HashMap. 1. Serialize HashMap containing generic types to JSON Serializing a hashmap to JSON […]
You may need custom serialization in java in may cases. For example, you have legacy java classes which you are not willing to modify for any reason. There can be some design constraints as well. Or even simply, the class is expected to be changed in future releases which could break the deserialization of previously […]
XMLEncoder class is used to serialize or encode a java object into XML file, while XMLDecoder is used to deserialize the xml file back to java object. Learn to use them in detail.
Knowing the difference between Externalizable vs Serializable is important in two aspects, one – if could be asked as an interview question, two – you can use the knowledge to make better informed decision for performance improvement for applying serialization into your application.
You can achieve more efficient serialization by implementing Externalizable interface and overriding it’s methods writeExternal() and readExternal().
In one of my previous post related to “Implementing Serializable interface in java“, Mr. Bitoo asked a good question “at the time of the deserializtion, how the JVM creates the object without calling the constructor??“. I thought of replying him in same post in a comment, but in another moment I thought of this a […]
Java SerialVersionUID example. Learn to create generate serialVersionUID for classes to be serialized. Learn to change serialversionuid correctly.
We all know that easiest way of deep cloning (with some performance overhead) or deep copy is Serialization. Java serialization involves serializing the object into bytes and from bytes to object again. I will suggest you to use in memory deep cloning whenever it is the only need and you don’t need to persist the […]
Java Serialization – Dos and don’ts for correct serialization and deserialization. Learn to use serialVersionUID, readObject and writeObject with example.