{"id":2171,"date":"2017-04-08T16:11:38","date_gmt":"2017-04-08T16:11:38","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=2171"},"modified":"2018-02-09T06:44:25","modified_gmt":"2018-02-09T06:44:25","slug":"why-we-need-serialization-version-id-in-serialization","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/why-we-need-serialization-version-id-in-serialization\/","title":{"rendered":"Why we need Serialization Version Id in Serialization"},"content":{"rendered":"<p>The whole concept of serialization works on versioning. If you save a class object using one version of the class but attempt to deserialize using a newer or different version of the class deserialization might fail.<\/p>\n<p>When you class structure can change in between you serialize the instance and go again to de-serialize it. Changed structure of class will cause JVM to give exception while de-serializing process.This problem can be solved only by adding a unique serial version id to class. It will prevent the compiler to throw the exception by telling that both classes are same, and will load the available instance variables only.<\/p>\n<p>The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender&#8217;s class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named &#8220;serialVersionUID&#8221; that must be static, final, and of type long<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n static final long serialVersionUID = 69L;\r\n<\/pre>\n<p>If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The whole concept of serialization works on versioning. If you save a class object using one version of the class but attempt to deserialize using a newer or different version of the class deserialization might fail. When you class structure can change in between you serialize the instance and go again to de-serialize it. Changed&hellip; <a href=\"https:\/\/codethataint.com\/blog\/why-we-need-serialization-version-id-in-serialization\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[204],"tags":[],"class_list":["post-2171","post","type-post","status-publish","format-standard","hentry","category-serialization"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=2171"}],"version-history":[{"count":4,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2171\/revisions"}],"predecessor-version":[{"id":2645,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2171\/revisions\/2645"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=2171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=2171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=2171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}