We help IT Professionals succeed at work.

NotSerializableException message for class wich implements Serializable

MarteJ
MarteJ asked
on
491 Views
Last Modified: 2012-05-04
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!!:-)
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2004

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

Can you post the reading code ?
CERTIFIED EXPERT
Top Expert 2016

Commented:
Also, is this a typo? (two pairs )

>>
      outputToATV.flush();
      outputToATV.close();
      outputToATV.flush();
      outputToATV.close()
>>
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
:)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.