title: Java serialization - incompatible serialVersionUID
body: <p>I understand the theory behind incompatible serialVersionUIDs (i.e. you can discriminate different compilation versions of the same class) but I am seeing an issue that I don't understand and doesn't fall into the obvious error causes (different compiled version of the same class).</p>
  
  <p>I am testing a serialization/deserialization process. All code is running on one machine, in the same VM, and both serialization and deserialization methods are using the same version of the compiled class. Serialization works fine. The class being serialized is quite complex, contains a number of other classes (java types and UDTs), and contains reference cycles. I haven't declared my own UID in any class. </p>
  
  <p>This is the code:</p>
  
  <pre><code>public class Test {
  
      public static void main(String[] args) throws Exception {
  
          ContextNode context = WorkflowBuilder.getSimpleSequentialContextNode();
          String contextString = BinarySerialization.serializeToString(context);
          ContextNode contextD = BinarySerialization.deserializeFromString(ContextNode.class, contextString);
      }
  }
  
  public class BinarySerialization {
  
      public static synchronized String serializeToString(Object obj) throws Exception {
          ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
          ObjectOutputStream oos = new ObjectOutputStream(byteStream);
          oos.writeObject(obj);
          oos.close();
          return byteStream.toString();
      }
  
      public static synchronized &lt;T&gt; T deserializeFromString(Class&lt;T&gt; type, String byteString) throws Exception {
          T object = null;
          ByteArrayInputStream byteStream = new ByteArrayInputStream(byteString.getBytes());
          ObjectInputStream in = new ObjectInputStream(byteStream);
          object = (T)in.readObject();
          in.close();
          return object;
      }
  }
  </code></pre>
  
  <p>I am getting an InvalidClassException (local class incompatible: stream classdesc serialVersionUID = -7189235121689378989, local class serialVersionUID = -7189235121689362093) when deserializing. </p>
  
  <p>What is the underlying issue? And how should I fix it?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit</strong>
  I should state the purpose of this. The serialized data will both need to be stored in a sqlite database and sent across the wire to other clients. If <code>String</code> is the wrong format for passing around the serialized data, what should I be using instead that will let me store and pass the data about? Thanks again.</p>