{"id":1612,"date":"2011-03-09T01:13:59","date_gmt":"2011-03-08T19:43:59","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1612"},"modified":"2011-03-09T01:13:59","modified_gmt":"2011-03-08T19:43:59","slug":"serialization-marshalling-deflating-in-java","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/serialization-marshalling-deflating-in-java\/","title":{"rendered":"Serialization \/ Marshalling \/ Deflating in JAVA"},"content":{"rendered":"<p>Writing Java Objects or keeping the state of Objects into DataBase or Files (In Binary Format) is known as <strong>Serialization or Marshalling or deflating.<\/strong><br \/>\nReading Java Objects back in Binary Format from file or Database is known as<strong> DeSerialization or UnMarshalling or inflating.<\/strong><\/p>\n<p><strong> <\/strong><\/p>\n<figure id=\"attachment_1614\" aria-describedby=\"caption-attachment-1614\" style=\"width: 474px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Serialization-Marshalling-deflating-DeSerialization-UnMarshalling-inflating.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1614 \" title=\"Serialization ,Marshalling ,deflating, DeSerialization ,UnMarshalling ,inflating\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Serialization-Marshalling-deflating-DeSerialization-UnMarshalling-inflating.jpg?resize=474%2C324&#038;ssl=1\" alt=\"Serialization ,Marshalling ,deflating, DeSerialization ,UnMarshalling ,inflating\" width=\"474\" height=\"324\" \/><\/a><figcaption id=\"caption-attachment-1614\" class=\"wp-caption-text\">Serialization \/Marshalling \/deflating - DeSerialization\/ UnMarshalling \/inflating<\/figcaption><\/figure>\n<p><strong><!--more-->Transient :<\/strong> If any variable is defined by using keyword &#8220;transient&#8221;\u009d, then object will not serialize that variable. During deserialization default value of that datatype will be set.<br \/>\n<strong> Static :<\/strong> as static variables are class level variables, so it is not serialzed as the object state.<\/p>\n<p>Example:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npackage com.G2.Serialization;\n\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.ObjectInputStream;\nimport java.io.ObjectOutputStream;\nimport java.io.Serializable;\n\nclass Home implements Serializable\n{\n\t transient int flatNo;\n\t String OwnerName;\n}\n\nclass Door extends Home\n{\n\tprivate boolean isDoubleLock;\n\tprivate String DoorMaterial;\n\tpublic void setValue(boolean isDLock,String dMaterial, int fNo,String Owner)\n\t{\n\t\tisDoubleLock = isDLock;\n\t\tDoorMaterial = dMaterial;\n\t\tflatNo = fNo;\n\t\tOwnerName = Owner;\n\t}\n\tpublic void Display()\n\t{\n\t\tSystem.out.println(&quot;Double Lock - &quot;+isDoubleLock);\n\t\tSystem.out.println(&quot;Material - &quot;+DoorMaterial);\n\t\tSystem.out.println(&quot;flat No - &quot;+flatNo);\n\t\tSystem.out.println(&quot;Owner Name - &quot;+OwnerName);\n\t}\n}\n\npublic class SerializationDemo {\n\tpublic static void main(String&#x5B;] args) throws FileNotFoundException, IOException,\nClassNotFoundException {\n\t\tObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(&quot;Demo.srl&quot;));\n\n\t\tDoor d = new Door();\n\t\td.setValue(true, &quot;Wood&quot;, 24, &quot;Minal Zaa&quot;);\n\t\tSystem.out.println(&quot; *** Serializing Object *** &quot;);\n\t\tout.writeObject(d);\n\n\t\tout.close();\n\n\t\tObjectInputStream in = new ObjectInputStream(new FileInputStream(&quot;Demo.srl&quot;));\n\t\tSystem.out.println(&quot; *** DeSerializing Object *** &quot;);\n\t\tDoor d1 = (Door) in.readObject();\n\t\td1.Display();\n\n\t\tin.close();\n\n\t}\n}\n<\/pre>\n<p><strong> Output:<\/strong><\/p>\n<blockquote><p>*** Serializing Object ***<\/p>\n<p>*** DeSerializing Object ***<br \/>\nDouble Lock &#8211; true<br \/>\nMaterial &#8211; Wood<br \/>\nflat No &#8211; 0<br \/>\nOwner Name &#8211; Minal Zaa<\/p><\/blockquote>\n<p><strong> Note from example:<\/strong><br \/>\nParent class implements interface &#8220;<strong>Serializable<\/strong>&#8220;\u009d and child class extends that, <strong>so child class automatically gets serialized.<\/strong><br \/>\nVariable &#8220;flatNo&#8221;\u009d is <strong>transient <\/strong>and therefore it is not serialized.<\/p>\n<p><a title=\"Externalization in Java\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/explain-externalizable-in-java\/\">further read &#8211; Externalization API of Java.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Concept of Serialization \/ Marshalling \/ Deflating in JAVA<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[329],"class_list":["post-1612","post","type-post","status-publish","format-standard","hentry","category-java","tag-java"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2061,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/explain-serialversionuid-in-java\/","url_meta":{"origin":1612,"position":0},"title":"Explain serialVersionUID in Java","author":"Jitendra","date":"April 20, 2011","format":false,"excerpt":"What is serialVersionUID and what is its need ?","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2049,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/explain-externalizable-in-java\/","url_meta":{"origin":1612,"position":1},"title":"Explain Externalizable in Java","author":"Jitendra","date":"April 20, 2011","format":false,"excerpt":"Explain Externalizable in Java","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2017,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/java-j2ee-interview-questions-1\/","url_meta":{"origin":1612,"position":2},"title":"Java &#8211; J2EE Interview Questions &#8211; 1","author":"Jitendra","date":"April 15, 2011","format":false,"excerpt":"JAVA - J2EE Interview Questions - 1, JAVA - J2EE Interview Questions - 1,custom tag JSP, Externalization , serialVersionUID, difference between interface and abstract class, iterate HashMap","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1750,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/create-xml-file-using-jaxp-and-transformation-apis\/","url_meta":{"origin":1612,"position":3},"title":"Create XML File using DOM Parser of JAXP and Transformation APIs","author":"Jitendra","date":"March 22, 2011","format":false,"excerpt":"Example of Creating XML File using JAXP and Transformation APIs","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3050,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/my-favorite-top-10-features-of-winter-13-release-salesforce\/","url_meta":{"origin":1612,"position":4},"title":"My Favorite Top 10 Features of Winter 13 release &#8211; Salesforce","author":"Jitendra","date":"August 24, 2012","format":false,"excerpt":"Dear Friends, I am very excited to write this article about the cool Winter 13 features which i have added in My List. There are lots of lots of new features added in this release and i have made the list of my top 10 favorite features. Yesterday Salesforce published\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce Winter 13 Release Notes","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/08\/Salesforce-Winter-13-Release-Notes-300x212.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3460,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/hibernate\/introduction-hibernate\/","url_meta":{"origin":1612,"position":5},"title":"Introduction to Hibernate","author":"Jitendra","date":"October 1, 2013","format":false,"excerpt":"Post by - Subhash Bhajankar What is the problem that hibernate is trying to solve? \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Let's take an example of simple class that you have in your application. Referring Image 1, we have Employee object in our java class which has six fields. In our running\u2026","rel":"","context":"In &quot;Hibernate&quot;","block_context":{"text":"Hibernate","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/hibernate\/"},"img":{"alt_text":"Necessity of Hibernate ","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/problem.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/problem.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/10\/problem.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1612"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1612\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}