title: Serializing/de-serializing with different classes using Msgpack (Java API)
body: <p>I'm currently experimenting with Msgpack to de-serialize an object graph using Msgpack but I am hitting problems.</p>
  
  <p>At the moment I have a simple hierachy consisting of two classes: <code>BaseMessage</code> and <code>PersonNew</code>. <code>BaseMessage</code> has a single Long field <code>id</code> with getters and setters. <code>PersonNew</code> has String fields <code>name</code> and <code>email</code> and inherits from <code>BaseMessage</code>.</p>
  
  <p>Originally <code>PersonOld</code> class had the <code>id</code> field and it serialized/de-serialized fine. However when tring to de-serialize from <code>PersonOld</code> (which had the <code>id</code>) to <code>PersonNew</code> class (which inherits the <code>id</code> from <code>BaseMessage</code>) I'm being hit with the error:</p>
  
  <pre><code>org.msgpack.MessageTypeException: Unexpected raw value
  </code></pre>
  
  <p>All the fields I'm using are private.</p>
  
  <p>Below is the sample code:</p>
  
  <pre class="lang-java prettyprint-override"><code>    PersonOld personOld = new PersonOld();
      personOld.setName("person");
      personOld.setEmail("person@email.com");
  
      MessagePack msgpack = new MessagePack();
      msgpack.register(PersonNew.class);
      msgpack.register(PersonOld.class);
  
      // Serialize using old person class
      byte[] personBytes = msgpack.write(personOld);
  
      ByteArrayInputStream in = new ByteArrayInputStream(personBytes);
      Unpacker unpacker = msgpack.createUnpacker(in);
  
      // Deserialize using new person class
      PersonNew deserializePerson = unpacker.read(PersonNew.class);
  </code></pre>
  
  <p>The reason I'd like to de-serialize to a newer class is because I want to see if it's possible to have older serialized data (e.g. in a persisted message queue) be compatible with newer classes (e.g. in case of class updates). I have attempted to even use the <code>@Optional</code> annotation on the <code>id</code> of the <code>BaseMessage</code> class but still doesn't work.</p>
  
  <p>Is it possible at all to de-serialize with a different class despite having the same fields?</p>
  
  <p>Regards,</p>
  
  <p>SNK</p>