title: Class Cast Exception from ObjectStreamClass to util.ArrayList
body: <p>I am trying to serialize my arraylist which holds multiple help group objects.  I know I am saving the file right, but I get a ClassCastException when trying to deserialize it. The below is being called from a HelpGroup.java class that does implement serializable as well.  The code below is actually found in a class called HelpGuide. Any help would be appreciated.</p>
  
  <p>stack trace</p>
  
  <pre><code>SEVERE: Servlet.service() for servlet [WebAppHelp] in context with path [/webapphelpui] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.util.ArrayList] with root cause
  java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.util.ArrayList
      at com.aais.helpguides.model.HelpGuide.readList(HelpGuide.java:70)
      at com.aais.helpguides.model.HelpGroup.selectHelpGroups(HelpGroup.java:131)
      at com.aais.helpguides.controller.WebAppController.showHelpGroups(WebAppController.java:43)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>HelpGuide.java</p>
  
  <pre><code>package com.aais.helpguides.model;
  
  import com.aais.helpguides.model.HelpGroup;
  
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.Serializable;
  import java.util.ArrayList;
  
  public class HelpGuide 
  {
      private ArrayList&lt;HelpGroup&gt; helpGroups;
  
      // default constructor
      public HelpGuide() 
      {
          this.helpGroups = new ArrayList&lt;HelpGroup&gt;();
      }
  
  
      public HelpGuide(ArrayList&lt;HelpGroup&gt; helpGroups)
      {
          this.helpGroups = new ArrayList&lt;HelpGroup&gt;(helpGroups);
  
      }
      public ArrayList&lt;HelpGroup&gt; getHelpGroups()
      {
          return helpGroups;
      }
  
      public void setHelpGroups(ArrayList&lt;HelpGroup&gt; helpGroups)
      {
          this.helpGroups = new ArrayList&lt;HelpGroup&gt;(helpGroups);
      }
  
      // save the current array list of help groups
          public void saveList(ArrayList&lt;HelpGroup&gt; helpGroups)
          {
  
              try
              {
                  FileOutputStream fileOut =  new FileOutputStream("C:/temp/listhelpgroups.ser");
                  ObjectOutputStream out = new ObjectOutputStream(fileOut);
                  out.writeObject(helpGroups);
                  out.close();
                  fileOut.close();
                  System.out.printf("Serialized data is saved in C:/temp/listhelpgroups.ser");
              }   
              catch(IOException i)
              {
                  i.printStackTrace();
              }
          }
  
          // read the list 
          public ArrayList&lt;HelpGroup&gt; readList()
          {
              ArrayList&lt;HelpGroup&gt; currentList = new ArrayList&lt;HelpGroup&gt;();
              try
              {
                  FileInputStream fis = new FileInputStream("C:/temp/listhelpgroups.ser");
                  ObjectInputStream ois = new ObjectInputStream(fis);
                  while(fis.read() != -1)
                  {
                      currentList = (ArrayList&lt;HelpGroup&gt;) ois.readObject();
                  }
              } 
              catch (ClassNotFoundException e) 
              {
                  e.printStackTrace();
              }
              catch (FileNotFoundException e) 
              {
                  e.printStackTrace();
              }
              catch (IOException e) 
              {
                  e.printStackTrace();
              }
              return currentList;
          }
  </code></pre>
  
  <p>class to be serialized</p>
  
  <pre><code>public class HelpGroup implements Serializable{
      @NotNull
      private long id;
      @NotNull
      private int sequence;
      @NotEmpty
      private String name;
  
      private String description;
  
      private ArrayList&lt;HelpSection&gt; helpSections;
  
      // default constructor
      public HelpGroup() {
          this.helpSections = new ArrayList&lt;HelpSection&gt;();
      }
  
      // constructor with specific arguments
      public HelpGroup(String name, long id, String description, int sequence) {
          this.description = description;
          this.id = id;
          this.name = name;
          this.sequence = sequence;
      }
  
      // get id
      public long getId() {
          return id;
      }
  
      // set id
      public void setId(long id) {
          this.id = id;
      }
  
      // get name
      public String getName() {
          return name;
      }
  
      // set name
      public void setName(String name) {
          this.name = name;
      }
  
      // get description
      public String getDescription() {
          return description;
      }
  
      // set description
      public void setDescription(String description) {
          this.description = description;
      }
  
      // get sequence; order in which they are listed
      public int getSequence() {
          return sequence;
      }
  
      // set the sequence
      public void setSequence(int sequence) {
          this.sequence = sequence;
      }
  </code></pre>