title: How to serialize ArrayList of objects?
body: <blockquote>
    <p>I want to serialize an arraylist of <strong>Item</strong> but it doesn't work....</p>
    
    <p>my <strong>Item</strong> class extends <strong>Stuff</strong> class and has some <em>subclasses</em>.</p>
    
    <p>all of my classes implement Serilalizable.</p>
    
    <p>i have this part :</p>
  
  <pre><code>try{
  // Serialize data object to a file
  ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("MyData.ser"));
  out.writeObject(myData);
  out.close();
  
  // Serialize data object to a byte array
  ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
  out = new ObjectOutputStream(bos) ;
  out.writeObject(myData);
  out.close();
  
  // Get the bytes of the serialized object
  byte[] buf = bos.toByteArray();
  } catch (IOException e) {
  }
  </code></pre>
    
    <p>my classes :</p>
  
  <pre><code>public class Stuff implements Serializeable{
  ....
  some protected fields
  .
  .
  }
  
  public class Item extends Stuff implements Serializable{
  ...
  ..
  .
  } and some subclasses of Item:
  
  public class FirstItem extends Item implements Serializable{
  ...
  }
  
  public class SecondItem extends Item implements Serializable{
  ...
  } ... I want to serialize an object contains ArrayList of &lt;Item&gt; that has objects of Item's subclasses (FirstItem,SecondItem,...)
  </code></pre>
    
    <p><strong>i think informations are sufficient...</strong></p>
  </blockquote>
  
  <p><strong>it's just a little mistake and now works correctly...
  I'm sorry for my stupid question.</strong></p>
  
  <p>Thank you for your answers.</p>