{"id":822,"date":"2022-08-09T04:12:41","date_gmt":"2022-08-09T04:12:41","guid":{"rendered":"https:\/\/datmt.com\/?p=822"},"modified":"2022-08-09T04:12:42","modified_gmt":"2022-08-09T04:12:42","slug":"java-serialization-fundamentals","status":"publish","type":"post","link":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/","title":{"rendered":"Java Serialization fundamentals"},"content":{"rendered":"\n<p>In this post, I will introduce the fundamentals of serialization in Java that you need to know.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Serializable interface<\/h2>\n\n\n\n<p>A class that doesn&#8217;t implement the Serializable interface cannot be serialized.<\/p>\n\n\n\n<p>In the <a href=\"https:\/\/datmt.com\/backend\/java\/java-serialization-examples\/\">previous post<\/a>, you can see that the <code>Car<\/code> and <code>Engine<\/code> classes both implement Serializable.<\/p>\n\n\n\n<p>The Serializable interface is a marker interface. That means it&#8217;s an interface without any method.<\/p>\n\n\n\n<p>Your classes only need to implement that interface to be serialized.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Serialization principles<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>An object is serializable if<ul><li>It implements Serializable<\/li><li>Its non-primitive fields&#8217; types must also implement Serializable or marked as <code>transient<\/code><\/li><\/ul><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>An array is serializable if all elements are serializable<\/li><li>To ignore a field, mark it as <code>transient<\/code><\/li><li>static fields are not serialized<\/li><\/ul>\n\n\n\n<p>Now, let&#8217;s examine these principles with some examples<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common methods<\/h2>\n\n\n\n<p>I&#8217;m going to reuse the <code>serializeObject<\/code> and <code>deserializeObject<\/code> in the previous post. Here they are for your convenience:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">    private static void serializeObject(Object object, String name) throws IOException {\n\n        try (FileOutputStream outputStream = new FileOutputStream(&quot;C:\\\\Users\\\\myn\\\\Downloads\\\\&quot; + name);\n             ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);) {\n\n            objectOutputStream.writeObject(object);\n        }\n    }\n\n    private static Object deserializeObject(String name) throws IOException, ClassNotFoundException {\n        try (FileInputStream fileInputStream = new FileInputStream(&quot;C:\\\\Users\\\\myn\\\\Downloads\\\\&quot; + name);\n             ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);) {\n\n            return objectInputStream.readObject();\n        }\n    }\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Transient<\/h2>\n\n\n\n<p>Let&#8217;s consider a Phone class that has Battery as a field. Phone is serializable but Battery isn&#8217;t.<\/p>\n\n\n\n<p>The Battery class<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">class Battery {\n   private int capacity;\n\n    public int getCapacity() {\n        return capacity;\n    }\n\n    public void setCapacity(int capacity) {\n        this.capacity = capacity;\n    }\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>The Phone class:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">class Phone implements Serializable {\n   private Battery battery;\n   private String model;\n   private String manufacturer;\n\n   public Phone(Battery battery, String model, String manufacturer) {\n       this.battery = battery;\n       this.model = model;\n       this.manufacturer = manufacturer;\n   }\n\n    @Override\n    public String toString() {\n        return &quot;Phone{&quot; +\n                &quot;battery=&quot; + battery +\n                &quot;, model='&quot; + model + '\\'' +\n                &quot;, manufacturer='&quot; + manufacturer + '\\'' +\n                '}';\n    }\n}\n<\/pre><\/div>\n\n\n\n<p>Let&#8217;s create a phone object and serialize it and store in a file using <code>serializeObject<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">    public static void main(String[] args) throws IOException {\n        \n        Battery battery = new Battery();\n        battery.setCapacity(300);\n        \n        Phone phone = new Phone(battery, &quot;iFruit 14&quot;, &quot;Fruit&quot;);\n        \n        serializeObject(phone, &quot;fruit&quot;);\n\n    }\n<\/pre><\/div>\n\n\n\n<p>What is the result of this operation?<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">Exception in thread &quot;main&quot; java.io.NotSerializableException: com.datmt.java_core.serialization.Battery\n\tat java.base\/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1197)\n\tat java.base\/java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1582)\n\tat java.base\/java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1539)\n\tat java.base\/java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1448)\n\tat java.base\/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1191)\n\tat java.base\/java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354)\n\tat com.datmt.java_core.serialization.TransientExample.serializeObject(TransientExample.java:28)\n\tat com.datmt.java_core.serialization.TransientExample.main(TransientExample.java:19)<\/pre><\/div>\n\n\n\n<p>From the log, you can see that basically, it says the class Battery is not serializable. <\/p>\n\n\n\n<p>If you mark the battery field as transient, the serialize process will work just fine.<\/p>\n\n\n\n<p>Let&#8217;s add <code>transient<\/code> to the battery field and try to serialize and deserialize the phone object again.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">    public static void main(String[] args) throws IOException, ClassNotFoundException {\n\n        Battery battery = new Battery();\n        battery.setCapacity(300);\n\n        Phone phone = new Phone(battery, &quot;iFruit 14&quot;, &quot;Fruit&quot;);\n\n        serializeObject(phone, &quot;fruit&quot;);\n\n        var phone2 = (Phone) deserializeObject(&quot;fruit&quot;);\n\n        System.out.println(phone2);\n    }\n<\/pre><\/div>\n\n\n\n<p>This is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"374\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" src=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-41-1024x374.png\" alt=\"Serialize and deserialize of transient fields\" class=\"wp-image-825\" srcset=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-41-1024x374.png 1024w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-41-300x109.png 300w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-41-768x280.png 768w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-41.png 1137w\" \/><figcaption>Serialize and deserialize transient fields<\/figcaption><\/figure>\n\n\n\n<p>As you can see, the battery field is null. This is expected since it wasn&#8217;t serialized in the serialization process. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Static field serialization<\/h2>\n\n\n\n<p>As mentioned above, static fields are not serialized. It is because static fields do not belong to any object instance. Instead, the fields belong to the class.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enum serialization<\/h2>\n\n\n\n<p>The enum class implements Serializable. Thus, you don&#8217;t need to implement Serializable again for your enums.<\/p>\n\n\n\n<p>Let&#8217;s declare some enums and add them as fields in the Phone class:<\/p>\n\n\n\n<p>New enums and type:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">\nenum PhoneType {\n    FLIP, TOUCH, FOLD;\n\n}\n\nenum ScreenType {\n     NOTCH(new Screen(&quot;NOTCH&quot;)),\n     DOT(new Screen(&quot;DOT&quot;));\n\n     private final Screen type;\n     private ScreenType(Screen type) {\n         this.type = type;\n     }\n\n    public Screen getType() {\n        return type;\n    }\n}\n\nclass Screen {\n    private String type;\n    public Screen(String type) {\n        this.type = type;\n    }\n}\n<\/pre><\/div>\n\n\n\n<p>The Phone class<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">class Phone implements Serializable {\n\n    private transient Battery battery;\n    private String model;\n    private String manufacturer;\n\n    private PhoneType engineType;\n\n    private ScreenType screenType;\n    public Phone(Battery battery, String model, String manufacturer) {\n        this.battery = battery;\n        this.model = model;\n        this.manufacturer = manufacturer;\n    }\n\n    public PhoneType getPhoneType() {\n        return engineType;\n    }\n\n    public void setPhoneType(PhoneType engineType) {\n        this.engineType = engineType;\n    }\n\n    public ScreenType getScreenType() {\n        return screenType;\n    }\n\n    public void setScreenType(ScreenType screenType) {\n        this.screenType = screenType;\n    }\n\n    @Override\n    public String toString() {\n        return &quot;Phone{&quot; +\n                &quot;battery=&quot; + battery +\n                &quot;, model='&quot; + model + '\\'' +\n                &quot;, manufacturer='&quot; + manufacturer + '\\'' +\n                '}';\n    }\n}\n<\/pre><\/div>\n\n\n\n<p>As you can see, PhoneType is a simple enum and ScreenType is a bit more complex with a constructor. <\/p>\n\n\n\n<p>Let&#8217;s create some phones and see how enum serialization\/deserialization works:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchFieldException {\n\n        Battery battery = new Battery();\n\n        Phone phone14 = new Phone(battery, &quot;iFruit 14&quot;, &quot;Fruit&quot;);\n        Phone phone13 = new Phone(battery, &quot;iFruit 13&quot;, &quot;Fruit&quot;);\n\n        phone14.setPhoneType(PhoneType.FLIP);\n        phone14.setScreenType(ScreenType.DOT);\n\n        phone13.setScreenType(ScreenType.DOT);\n\n        System.out.println(phone13.getScreenType() == phone14.getScreenType());\n        serializeObject(phone14, &quot;phone14&quot;);\n        serializeObject(phone13, &quot;phone13&quot;);\n\n        var phone14_restored = (Phone) deserializeObject(&quot;phone14&quot;);\n        var phone13_restored = (Phone) deserializeObject(&quot;phone13&quot;);\n\n        System.out.println(phone14_restored.getPhoneType());\n        System.out.println(phone14_restored.getScreenType() == phone13_restored.getScreenType());\n    }\n<\/pre><\/div>\n\n\n\n<p>Let&#8217;s pay attention to lines 13 and 21. What do you think the results would be?<\/p>\n\n\n\n<p>You may think line 13 produces <code>true<\/code> and line 21 produces <code>false<\/code>.<\/p>\n\n\n\n<p>This is the result:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"353\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" src=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-42.png\" alt=\"Enum fields serialization\" class=\"wp-image-827\" srcset=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-42.png 969w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-42-300x109.png 300w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-42-768x280.png 768w\" \/><figcaption>Enum fields serialization<\/figcaption><\/figure>\n\n\n\n<p>As you can see, after serialization and deserialization, enum fields comparison works as expected. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"656\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" src=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-43-1024x656.png\" alt=\"All enums refer to the same object\" class=\"wp-image-828\" srcset=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-43-1024x656.png 1024w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-43-300x192.png 300w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-43-768x492.png 768w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-43.png 1187w\" \/><figcaption>All enums refer to the same object<\/figcaption><\/figure>\n\n\n\n<p>As you can see, the ScreenType object of every phone (before and after deserialization) points to the same object. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Serialization with changes<\/h2>\n\n\n\n<p>Your programs evolve, and so do your classes. Consider a ComputerMouse class that has the following fields and methods:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">class ComputerMouse implements Serializable {\n    private String manufacturer; \n    public ComputerMouse(String manufacturer) {\n        this.manufacturer = manufacturer;\n    }\n\n    public String getManufacturer() {\n        return manufacturer;\n    }\n}<\/pre><\/div>\n\n\n\n<p>Let&#8217;s create an instance of this class and save it in a file called old_mouse:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchFieldException {\n        ComputerMouse mouse = new ComputerMouse(&quot;Genius&quot;);\n\n        serializeObject(mouse, &quot;old_mouse&quot;);\n    }\n<\/pre><\/div>\n\n\n\n<p>Let&#8217;s say the class evolves and it now has some new fields and methods:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">class ComputerMouse implements Serializable {\n    private String manufacturer;\n    private String model;\n    public ComputerMouse(String manufacturer, String model) {\n        this.manufacturer = manufacturer;\n        this.model = model;\n    }\n\n    public String getModel() {\n        return model;\n    }\n\n    public String getManufacturer() {\n        return manufacturer;\n    }\n}\n<\/pre><\/div>\n\n\n\n<p>What will happen if I deserialize the &#8220;old_mouse&#8221; and cast to this new class?<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchFieldException {\n\n        var mouseRestored = (ComputerMouse) deserializeObject(&quot;old_mouse&quot;);\n    }\n<\/pre><\/div>\n\n\n\n<p>The deserialization fails and you will see an error message similar to this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">Exception in thread &quot;main&quot; java.io.InvalidClassException: com.datmt.java_core.serialization.ComputerMouse; local class incompatible: stream classdesc serialVersionUID = -1599228600573436250, local class serialVersionUID = 8005313661126509844\n\tat java.base\/java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:728)\n\tat java.base\/java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:2062)\n\tat java.base\/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1909)\n\tat java.base\/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2235)\n\tat java.base\/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1744)\n\tat java.base\/java.io.ObjectInputStream.readObject(ObjectInputStream.java:514)\n\tat java.base\/java.io.ObjectInputStream.readObject(ObjectInputStream.java:472)\n\tat com.datmt.java_core.serialization.TransientExample.deserializeObject(TransientExample.java:31)\n\tat com.datmt.java_core.serialization.TransientExample.main(TransientExample.java:15)\n\nProcess finished with exit code 1<\/pre><\/div>\n\n\n\n<p>It basically means the serialized object was from a class with a different serial number. <\/p>\n\n\n\n<p>If you want to make this work, you must get the fingerprint of the old class and set it in the new class or, if you just get started, just set the static, final long variable named <code>serialVersionUID<\/code> to the class.<\/p>\n\n\n\n<p>Let&#8217;s switch the class to the old one (without the new fields) then create an instance and serialize it again:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">class ComputerMouse implements Serializable {\n\n    public static final long serialVersionUID = 10000L;\n    private String manufacturer;\n    public ComputerMouse(String manufacturer) {\n        this.manufacturer = manufacturer;\n    }\n\n\n    public String getManufacturer() {\n        return manufacturer;\n    }\n}\n\npublic static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchFieldException {\n  ComputerMouse mouse = new ComputerMouse(&quot;Genius&quot;);\n  serializeObject(mouse, &quot;old_mouse&quot;);\n}\n<\/pre><\/div>\n\n\n\n<p>Now, let&#8217;s add new fields and methods to the <code>ComputerMouse<\/code> class and deserialize &#8220;old_mouse&#8221;:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">class ComputerMouse implements Serializable {\n\n    public static final long serialVersionUID = 10000L;\n    private String manufacturer;\n    private String model;\n    public ComputerMouse(String manufacturer, String model) {\n        this.manufacturer = manufacturer;\n        this.model = model;\n    }\n\n    public String getModel() {\n        return model;\n    }\n\n    public String getManufacturer() {\n        return manufacturer;\n    }\n}\n\npublic static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchFieldException {\n  var mouseRestored = deserializeObject(&quot;old_mouse&quot;);\n\n  assert mouseRestored != null;\n\n}\n<\/pre><\/div>\n\n\n\n<p>The code ran successfully without any exception.<\/p>\n\n\n\n<p>If I turn on the debug mode in my IDE (intellij), I can see the values of the fields:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"356\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" src=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-44-1024x356.png\" alt=\"Deserialization with changes\" class=\"wp-image-829\" srcset=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-44-1024x356.png 1024w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-44-300x104.png 300w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-44-768x267.png 768w, https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/image-44.png 1172w\" \/><figcaption>Deserialization with changes<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this post, I&#8217;ve demonstrated the fundamentals of Serialization in java. You&#8217;ve learned how serialization works, how to deal with non-serializable fields, and how to cope with class changes. <\/p>\n\n\n\n<p>In the next post, you will learn how to extend\/customize the serialization operation using method overriding and Externalizable<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I will introduce the fundamentals of serialization in Java that you need to know. The Serializable interface A class that doesn&#8217;t implement the Serializable interface cannot be serialized. In the previous post, you can see that the Car and Engine classes both implement Serializable. The Serializable interface is a marker interface. That &#8230; <a title=\"Java Serialization fundamentals\" class=\"read-more\" href=\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/\" aria-label=\"Read more about Java Serialization fundamentals\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":830,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[4],"tags":[73,121],"class_list":["post-822","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java-core","tag-java-serialization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Serialization fundamentals - datmt<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Serialization fundamentals - datmt\" \/>\n<meta property=\"og:description\" content=\"In this post, I will introduce the fundamentals of serialization in Java that you need to know. The Serializable interface A class that doesn&#8217;t implement the Serializable interface cannot be serialized. In the previous post, you can see that the Car and Engine classes both implement Serializable. The Serializable interface is a marker interface. That ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/\" \/>\n<meta property=\"og:site_name\" content=\"datmt\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-09T04:12:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-09T04:12:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"\u0110\u1ea1t Tr\u1ea7n\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u0110\u1ea1t Tr\u1ea7n\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/\"},\"author\":{\"name\":\"\u0110\u1ea1t Tr\u1ea7n\",\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"headline\":\"Java Serialization fundamentals\",\"datePublished\":\"2022-08-09T04:12:41+00:00\",\"dateModified\":\"2022-08-09T04:12:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/\"},\"wordCount\":697,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"image\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg\",\"keywords\":[\"java core\",\"java serialization\"],\"articleSection\":[\"java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/\",\"url\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/\",\"name\":\"Java Serialization fundamentals - datmt\",\"isPartOf\":{\"@id\":\"https:\/\/datmt.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg\",\"datePublished\":\"2022-08-09T04:12:41+00:00\",\"dateModified\":\"2022-08-09T04:12:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#primaryimage\",\"url\":\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg\",\"contentUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg\",\"width\":1200,\"height\":628,\"caption\":\"Java Serialization fundamentals\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/datmt.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Serialization fundamentals\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/datmt.com\/#website\",\"url\":\"https:\/\/datmt.com\/\",\"name\":\"datmt\",\"description\":\"Hands on projects\",\"publisher\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/datmt.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e\",\"name\":\"\u0110\u1ea1t Tr\u1ea7n\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg\",\"contentUrl\":\"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg\",\"width\":512,\"height\":512,\"caption\":\"\u0110\u1ea1t Tr\u1ea7n\"},\"logo\":{\"@id\":\"https:\/\/datmt.com\/#\/schema\/person\/image\/\"},\"description\":\"I build softwares that solve problems. I also love writing\/documenting things I learn\/want to learn.\",\"sameAs\":[\"https:\/\/datmt.com\"],\"url\":\"https:\/\/datmt.com\/author\/mtdat171_c\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Serialization fundamentals - datmt","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/","og_locale":"en_US","og_type":"article","og_title":"Java Serialization fundamentals - datmt","og_description":"In this post, I will introduce the fundamentals of serialization in Java that you need to know. The Serializable interface A class that doesn&#8217;t implement the Serializable interface cannot be serialized. In the previous post, you can see that the Car and Engine classes both implement Serializable. The Serializable interface is a marker interface. That ... Read more","og_url":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/","og_site_name":"datmt","article_published_time":"2022-08-09T04:12:41+00:00","article_modified_time":"2022-08-09T04:12:42+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg","type":"image\/jpeg"}],"author":"\u0110\u1ea1t Tr\u1ea7n","twitter_card":"summary_large_image","twitter_misc":{"Written by":"\u0110\u1ea1t Tr\u1ea7n","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#article","isPartOf":{"@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/"},"author":{"name":"\u0110\u1ea1t Tr\u1ea7n","@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"headline":"Java Serialization fundamentals","datePublished":"2022-08-09T04:12:41+00:00","dateModified":"2022-08-09T04:12:42+00:00","mainEntityOfPage":{"@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/"},"wordCount":697,"commentCount":0,"publisher":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"image":{"@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#primaryimage"},"thumbnailUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg","keywords":["java core","java serialization"],"articleSection":["java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/","url":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/","name":"Java Serialization fundamentals - datmt","isPartOf":{"@id":"https:\/\/datmt.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#primaryimage"},"image":{"@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#primaryimage"},"thumbnailUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg","datePublished":"2022-08-09T04:12:41+00:00","dateModified":"2022-08-09T04:12:42+00:00","breadcrumb":{"@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#primaryimage","url":"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg","contentUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2022\/08\/Java-Serialization-fundamentals.jpg","width":1200,"height":628,"caption":"Java Serialization fundamentals"},{"@type":"BreadcrumbList","@id":"https:\/\/datmt.com\/backend\/java\/java-serialization-fundamentals\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/datmt.com\/"},{"@type":"ListItem","position":2,"name":"Java Serialization fundamentals"}]},{"@type":"WebSite","@id":"https:\/\/datmt.com\/#website","url":"https:\/\/datmt.com\/","name":"datmt","description":"Hands on projects","publisher":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/datmt.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/datmt.com\/#\/schema\/person\/7736566e3758f424a11fd53f581c4b5e","name":"\u0110\u1ea1t Tr\u1ea7n","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/datmt.com\/#\/schema\/person\/image\/","url":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg","contentUrl":"https:\/\/datmt.com\/wp-content\/uploads\/2023\/03\/cropped-profile.jpg","width":512,"height":512,"caption":"\u0110\u1ea1t Tr\u1ea7n"},"logo":{"@id":"https:\/\/datmt.com\/#\/schema\/person\/image\/"},"description":"I build softwares that solve problems. I also love writing\/documenting things I learn\/want to learn.","sameAs":["https:\/\/datmt.com"],"url":"https:\/\/datmt.com\/author\/mtdat171_c\/"}]}},"_links":{"self":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/comments?post=822"}],"version-history":[{"count":2,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/822\/revisions"}],"predecessor-version":[{"id":831,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/posts\/822\/revisions\/831"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/media\/830"}],"wp:attachment":[{"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/media?parent=822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/categories?post=822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datmt.com\/wp-json\/wp\/v2\/tags?post=822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}