Servlet FileUpload: how to read custom type object from multitype form?
<p>I use <code>org.apache.commons.fileupload</code> to read file from multitype form. The question is how to read custom type object from this form. I tried to use <code>fileitem.get()</code> which gives byte representation of this field, but during deserialization i had an exception <code>java.io.StreamCorruptedException: invalid stream header: 62792E74</code>. 
<code>fileitem.getString()</code> gives following representation of this object:</p>

<pre><code>by.training.sixthgroup.model.Genre@716e2626
</code></pre>

<p>Some code also can help you</p>

<pre><code>Genre genre = (Genre) deserialize(fileItem.get());

public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException {
        ByteArrayInputStream in = new ByteArrayInputStream(data);
        ObjectInputStream is = new ObjectInputStream(in);
        return is.readObject();
}
</code></pre>