title: How to serialize an object into a string
body: <p>I am able to serialize an object into a file and then restore it again as is shown in the next code snippet. I would like to serialize the object into a string and store into a database instead. Can anyone help me?</p>
  
  <pre><code>LinkedList&lt;Diff_match_patch.Patch&gt; patches = // whatever...
  FileOutputStream fileStream = new FileOutputStream("foo.ser");
  ObjectOutputStream os = new ObjectOutputStream(fileStream);
  os.writeObject(patches1);
  os.close();
  
  FileInputStream fileInputStream = new FileInputStream("foo.ser");
  ObjectInputStream oInputStream = new ObjectInputStream(fileInputStream);
  Object one = oInputStream.readObject();
  LinkedList&lt;Diff_match_patch.Patch&gt; patches3 = (LinkedList&lt;Diff_match_patch.Patch&gt;) one;
  os.close();
  </code></pre>