Link to home
Start Free TrialLog in
Avatar of MarteJ
MarteJ

asked on

NotSerializableException message for class wich implements Serializable

Hi,

I have an application communicating with a servlet. The servlet passes a Vector of objects of the class AnnoTemplate. This class implements Serializable. But I still get the following exception:

java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: triq_adb.atv.gui.AnnoTemplate
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1278)
      at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1603)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1271)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
etc.

It used to work, but suddenly I get an exception. AnnoTemplate contains only int's, boolean's and String's, so I assume I don't need to let other classes implement Serializable.

My servlet:

    public void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {

    try {
      ObjectOutputStream outputToATV = new ObjectOutputStream(response.getOutputStream());
      Vector _templates = new Vector();
      ...
      //Successfull reading of xml file with JAXB, createing objects of AnnoTemplate by calling setAnnoTemplate() and adding these to _templates Vector.
      ...      
      outputToATV.writeObject(_templates);
      outputToATV.flush();
      outputToATV.close();
      outputToATV.flush();
      outputToATV.close()
   
    } catch(Exception x) {
      x.printStackTrace();
    }



AnnoTemplate class:
   
package triq_adb.atv.gui;
import java.io.Serializable;

public class AnnoTemplate implements Serializable {
 
  // public static final int's and String's
 
  private String _name;
  private String _type;
  private String _category;
  private String _remark;
  private String _severity;
  private boolean _pending;

  public AnnoTemplate() {

       // Initialize the annotation template
      _name = new String("");
      _type = new String("");
      _category = new String("");
      _remark = new String("");
      _severity = 0;
      _pending = false;
  }

  public void setAnnoTemplate(String name, String type, String category, String remark,
                              String severity) {
    _setName(name);
    _setType(type);
    _setCategory(category);
    _setRemark(remark);
    _setSeverity(severity);
    _setSeismicDataType(seismicDataType);
  }

    private void _setName(String s) {
    _name = s;
  }

 public String getName() {
      return _name;
  }

 private void _setType(String s) {
    _type = s;
  }

  public String getType() {
      return _type;
  }

   private void _setCategory(String s) {
    _category = s;
  }

  public String getCategory() {
      return _category;
  }

 private void _setRemark(String s) {
    _remark = s;
  }

  public String getRemark() {
      return _remark;
  }

  private void _setSeverity(String s) {
    _severity = s;
  }

public String getSeverity() {
    return _severity;
  }

  private void _setPending(boolean flag)  {
    _pending = flag;
  }

 public boolean getPending() {
    return _pending;
  }
}


Greatful for help, cause I am stuck!!:-)
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Webstorm
Webstorm

>>     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1278)

Can you post the reading code ?
Also, is this a typo? (two pairs )

>>
      outputToATV.flush();
      outputToATV.close();
      outputToATV.flush();
      outputToATV.close()
>>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)