title: Java serialization to string
body: <p>I have the following declaration of the static type <code>Object</code>:</p>
  
  <pre><code>Integer typeId;
  //Obtaining typeId
  Object containerObject = ContainerObjectFactory.create(typeId);
  </code></pre>
  
  <p>The factory can produce different types of <code>container objects</code>, e.g. <code>Date</code>, <code>Integer</code>, <code>BigDecimal</code> and so forth.</p>
  
  <p>Now, after creating the <code>containerObejct</code> I need to serialize it to an object of type <code>String</code> and store it into a database with hibernate. I'm not going to provide Object-relational mapping because it doesn't relate to the question directly. </p>
  
  <p>Well, what I want to do is to serialize the <code>containerObject</code> depending on it runtime-type and desirialize it later with the type it was serialized. Is it ever possible? Could I use <code>xml</code>-serialization for those sakes?</p>