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: 
IMO, serialization of `Enumeration` does not really make much sense. An `Enumeration` is merely a floating view on top of a data structure or other business logic. In order to serialize, you would better stick to serializing the backing interface. To visualize what I'm writing, I set up a little code snippet:

```
import java.io.*;
import java.util.*;

import javax.swing.tree.TreePath;

public class EnumTest {

  public class MyEnumerator<T> {

    // set holding data
    List<T> data;

    public MyEnumerator(List<T> data) {
      this.data = data;
    }

    public List<T> getData() {
      return data;
    }

    public Enumeration<T> enumerate() {
      return new Enumeration<T>() {
        transient int i = 0;

        @Override
        public boolean hasMoreElements() {
          return i < data.size();
        }

        @Override
        public T nextElement() {
          return data.get(i++);
        }
      };
    }
  }

  public EnumTest() throws Exception {
    List<TreePath> TreePaths = Arrays.asList(new TreePath[] { new TreePath("3"), new TreePath("4"), new TreePath("5") });
    MyEnumerator<TreePath> myEnum1 = new MyEnumerator<TreePath>(TreePaths);
    print(myEnum1);

    FileOutputStream fos = new FileOutputStream("test.out");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(myEnum1.getData());
    oos.close();
    fos.close();

    System.out.println("* Serialization complete");

    FileInputStream fis = new FileInputStream("test.out");
    ObjectInputStream ois = new ObjectInputStream(fis);
    @SuppressWarnings("unchecked")
    List<TreePath> data = (List<TreePath>) ois.readObject();
    MyEnumerator<TreePath> myEnum2 = new MyEnumerator<TreePath>(data);
    print(myEnum2);

    System.out.println("* Deserialization complete");
  }

  private void print(MyEnumerator<TreePath> myEnum1) {
    Enumeration<TreePath> enm = myEnum1.enumerate();
    while (enm.hasMoreElements()) {
      System.out.println(enm.nextElement());
    }
  }

  public static void main(String[] args) throws Exception {
    new EnumTest();
  }
}

```

This works around the topic of serializing the `Enumeration` itself by persisting the contained data and reconstructing the wrapper class `MyEnumerator` afterwards. Through the serialization / deserialization loop you will get a different object which is however semantically identical.
For your code to work TreePath also has to be serializable, since the elements of pathList are TreePath objects.