Question: How could I `serialize` `Enumeration` object to a file and then `deserialize` it? I tried to convert it to `ArrayList` but this option doesn't work for me. I tried the following code:

```
FileOutputStream fos            = null;
ObjectOutputStream outs         = null;
Enumeration<TreePath> stateEnum = com.jidesoft.tree.TreeUtils.saveExpansionStateByTreePath(tree);
ArrayList<TreePath> pathList    = new ArrayList<TreePath>();

while(stateEnum.hasMoreElements()){
    pathList.add(stateEnum.nextElement());
}
try {
    fos = new FileOutputStream(TREE_STATE_FILE);
    outs = new ObjectOutputStream(fos);
    outs.writeObject(pathList);
    outs.close();
} catch (IOException e) {
    _log.info("Failed to create " + TREE_STATE_FILE + " file: ", e);
}

```

But when I tried to `serialize` it I get nulls.
Thanks

Answer: 
Im not sure if this what you mean but take a look at this code:

```
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.NoSuchElementException;

@SuppressWarnings("unchecked")
public class SerializableEnumeration
   extends ArrayList
   implements Enumeration
{
   /** The serialVersionUID */
   private static final long serialVersionUID = 8678951571196067510L;
   private int index;

   public SerializableEnumeration () {
      index = 0;
   }

   public SerializableEnumeration (Collection c) {
      super(c);
      index = 0;
   }

   public SerializableEnumeration (int initialCapacity) {
      super(initialCapacity);
      index = 0;
   }

   public boolean hasMoreElements() {
      return (index < size());
   }

   public Object nextElement() throws NoSuchElementException
   {
      try {
         Object nextObj = get(index);
         index++;
         return nextObj;
      }
      catch (IndexOutOfBoundsException e) {
         throw new NoSuchElementException();
      }
   }

   private void writeObject(java.io.ObjectOutputStream out)
      throws java.io.IOException
   {
      // the only thing to write is the index field
      out.defaultWriteObject();
   }

   private void readObject(java.io.ObjectInputStream in)
      throws java.io.IOException, ClassNotFoundException
   {
      in.defaultReadObject();
   }
}

```

From [here](http://www.java2s.com/Tutorial/Java/0140__Collections/SerializableEnumeration.htm)
For your code to work TreePath also has to be serializable, since the elements of pathList are TreePath objects.