title: Reading and Writing (Serializing) static nested class object in different classes
body: <p>I want to serialize a Map object which contains a static nested CustomClass object as its value.</p>
  
  <pre><code>public class A{
  
      static Map&lt;String, CustomClass&gt; map = new HashMap&lt;&gt;();
  
      public static void main(String[] args) {
          map.put("ABC", new CustomClass(1, 2L, "Hello"));
          writeToFile();
      }
  
      private static void writeToFile() throws IOException, ClassNotFoundException {
          ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("file.ser"));
          out.writeObject(map);
      }
  
      private static class CustomClass implements Serializable {
          int x;
          long y;
          String z;
          private static final long serialVersionUID = 87923834787L;
          private CustomClass (int x, long y, String z) {
           .....
          }
      }
  
  }
  
  
  public class B {
  
      static Map&lt;String, CustomClass&gt; map = new HashMap&lt;&gt;();
  
      public static void main( String[] args) {
          readFromFile();
      }
  
      private static void readFromFile() throws IOException, ClassNotFoundException {
          ObjectInputStream out = new ObjectInputStream(new FileInputStream("file.ser"));
          map = out.readObject(); // ClassNotFoundException occured
      }
  
      private static class CustomClass implements Serializable {
          int x;
          long y;
          String z;
          private static final long serialVersionUID = 87923834787L;
          private CustomClass (int x, long y, String z) {
           .....
          }
  
          //some utility methods
          ....
      }
  
  }
  </code></pre>
  
  <p>When I am trying to read the serialized Map object, it is throwing the ClassNotFoundException. Is it because the same nested class defined under different class will have different name or version?</p>
  
  <p>What could be the possible solution for that problem. 
  Thanks</p>