Serialize Java Object into String using UTF-8
<p>I am trying to write a function which serialize an Java object into a String using UTF-8 encoding. This is my implementation:</p>

<pre><code>public static String serializeToString(DefaultMutableTreeNode tree) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        ObjectOutput out = new ObjectOutputStream(byteArrayOutputStream);
        out.writeObject(tree);
        return byteArrayOutputStream.toString("UTF-8");
    } catch (IOException e) {
        return null;
    }
}
</code></pre>

<p>However, it doesn't seem to work. I tried to pass the resulting String into a database which only accept UTF-8 encoding but failed with an error with encoding problem.</p>

<p>My questions are:</p>

<ol>
<li>What is the problem of my implementation?</li>
<li>How can I examine if the resulting String is in UTF-8 or not?</li>
</ol>

<p>Many thanks</p>

<p>Regards</p>
