469,330 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

java.io.NotSerializableException:

madhoriya22
252 100+
Hi,
I am getting this exception while deploying my web application. It is occuring for the attributes which I have set for the session. Here is the method which sets the session attribues :----
Expand|Select|Wrap|Line Numbers
  1. protected void showIndexPage(HttpServletRequest request, HttpServletResponse response)
  2.     throws ServletException, IOException{
  3.  
  4.         PrintWriter out = response.getWriter();
  5.         HttpSession session = request.getSession(true);
  6.         response.setContentType("text/html;charset=UTF-8");
  7.         System.out.println("Inside showIndexPage() method");
  8.  
  9.         DAOFactory mysqlFactory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
  10.         System.out.println("below DAOFactory object------------->>");
  11.         OffshoreResourceDAO offshoreResourceDAO = mysqlFactory.getOffshoreResourceDAO();
  12.         Vector offshoreResourceVOList = offshoreResourceDAO.getResource();
  13.  
  14.         ClientResourceDAO clientResourceDAO = mysqlFactory.getClientResourceDAO();
  15.         Vector clientResourceVOList = clientResourceDAO.getClientResource();
  16.  
  17.         WorkPackageDetailsDAO workPackageDetailsDAO = mysqlFactory.getWorkPackageDetailsDAO();
  18.         Vector workPackageDetailsList = workPackageDetailsDAO.getWorkPackageDetails();
  19.         System.out.println("WorkPackageDetails are:"+workPackageDetailsList);
  20.  
  21.         Vector weekList = weekFinder();
  22.         System.out.println("Week List is:"+weekList);
  23.  
  24.         session.setAttribute("OffshoreResourceList",offshoreResourceVOList);
  25.         session.setAttribute("ClientResourceList", clientResourceVOList);
  26.         session.setAttribute("WorkPackageDetailsList", workPackageDetailsList);
  27.         session.setAttribute("WeekList", weekList);
  28.         request.getRequestDispatcher("index.jsp").forward(request,response);
  29.  
  30.         out.close();
  31.     }
  32.  
The attributes for which I am getting this exception are OffshoreResourceList,ClientResourceList,WorkPackag eDetailsList. All these are Vectors.While throwing exception, this warning is comin:---
Expand|Select|Wrap|Line Numbers
  1. WARNING: Cannot serialize session attribute OffshoreResourceList for session 5F8A4B888C40A6D0C72FB2B67A60A641
  2.  
How I can remove this exception.
Thanks and regards,
madhoriya
Jul 27 '07 #1
11 33258
JosAH
11,448 Expert 8TB
Make your OffshoreResourceList et al implement the Serializable interface. This
is extremely easy because that interface doesn't define any methods, so simply
do this:

Expand|Select|Wrap|Line Numbers
  1. public class OffshoreResourceList implements Serializable {
  2.    ...
  3. }
  4.  
Do the same for all the other classes that can't be serialized now.

kind regards,

Jos
Jul 27 '07 #2
madhoriya22
252 100+
Make your OffshoreResourceList et al implement the Serializable interface. This
is extremely easy because that interface doesn't define any methods, so simply
do this:

Expand|Select|Wrap|Line Numbers
  1. public class OffshoreResourceList implements Serializable {
  2.    ...
  3. }
  4.  
Do the same for all the other classes that can't be serialized now.

kind regards,

Jos
Hi Jos,
It's Ok. But I have read the Vector class documentation...It already implements the serializabe interface. Then why we have to serialize it again in this class

Thanks and regards,
madhoriya
Jul 27 '07 #3
JosAH
11,448 Expert 8TB
Hi Jos,
It's Ok. But I have read the Vector class documentation...It already implements the serializabe interface. Then why we have to serialize it again in this class

Thanks and regards,
madhoriya
Ah, ok, then the error diagnostic indicates that one of the members you've put
in that Vector doesn't implement the Serializable interface. I didn't know that
your class was a Vector itself.

kind regards,

Jos
Jul 27 '07 #4
madhoriya22
252 100+
Ah, ok, then the error diagnostic indicates that one of the members you've put
in that Vector doesn't implement the Serializable interface. I didn't know that
your class was a Vector itself.

kind regards,

Jos
Hi Jos,
Then what i have to do to remove this exception. See what I am putting in this vector is object of a Value Object class.... which is made of getters and setters methods.
These objects contains the values fetched from the database means every object has his ints, strings, double etc....

Thanks and regards,
madhoriya
Jul 27 '07 #5
JosAH
11,448 Expert 8TB
Hi Jos,
Then what i have to do to remove this exception. See what I am putting in this vector is object of a Value Object class.... which is made of getters and setters methods.
These objects contains the values fetched from the database means every object has his ints, strings, double etc....

Thanks and regards,
madhoriya
It's simple:

Expand|Select|Wrap|Line Numbers
  1. public class ValueObject implements Serializable {
  2.    ...
  3. }
  4.  
The ObjectInputStream and ObjectOutputStream explicitly check whether or not
a to be serialized object implements that interface; if not: *boink* they throw
that Exception.

So basically, an object (or a class) is Serializable if it implements the Serializable
interface itself and all of its members are Serializable too; primitives are always
Serializable.

kind regards,

Jos
Jul 27 '07 #6
madhoriya22
252 100+
It's simple:

Expand|Select|Wrap|Line Numbers
  1. public class ValueObject implements Serializable {
  2.    ...
  3. }
  4.  
The ObjectInputStream and ObjectOutputStream explicitly check whether or not
a to be serialized object implements that interface; if not: *boink* they throw
that Exception.

So basically, an object (or a class) is Serializable if it implements the Serializable
interface itself and all of its members are Serializable too; primitives are always
Serializable.

kind regards,

Jos
Hi Jos,
Got it !! Thanks ...

regards,
madhoriya
Jul 27 '07 #7
JosAH
11,448 Expert 8TB
Hi Jos,
Got it !! Thanks ...

regards,
madhoriya
You're welcome of course; does it work now?

kind regards,

Jos

ps. You could write a little article about it of course; put it in the Editor's Corner
where I take care of the typos so we can put it in the Java Articles section
afterwards. Just a concise article about Serialization not a (verbatim) copy of
the text in the API documentation ...<hint hint/>
Jul 27 '07 #8
madhoriya22
252 100+
You're welcome of course; does it work now?

kind regards,

Jos

ps. You could write a little article about it of course; put it in the Editor's Corner
where I take care of the typos so we can put it in the Java Articles section
afterwards. Just a concise article about Serialization not a (verbatim) copy of
the text in the API documentation ...<hint hint/>
Hi Jos,
Yep it worked. I vil think about your suggestion. Problem is work load.

Thanks and regards,
madhoriya
Jul 27 '07 #9
JosAH
11,448 Expert 8TB
Hi Jos,
Yep it worked. I vil think about your suggestion. Problem is work load.

Thanks and regards,
madhoriya
Take it easy; there's no pressure or time limit. Writing a good article under
pressure had never succeeded before.

kind regards,

Jos
Jul 27 '07 #10
madhoriya22
252 100+
Take it easy; there's no pressure or time limit. Writing a good article under
pressure had never succeeded before.

kind regards,

Jos
Hi Jos,
Again Thanks for ur suggestion.
I vil surely do it when i vill be free minded. I really want to do it

thanks and regards,
madhoriya
Jul 27 '07 #11
JosAH
11,448 Expert 8TB
Hi Jos,
Again Thanks for ur suggestion.
I vil surely do it when i vill be free minded. I really want to do it

thanks and regards,
madhoriya
Thanks for your good intentions; I appreciate it a lot; and realize: there's no
hurry and we both can take care of any hurdles if that are any. It can be a nice
article.

kind regards,

Jos
Jul 27 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Michael | last post: by
reply views Thread by Ravi Tallury | last post: by
1 post views Thread by ptaz | last post: by
reply views Thread by Markus Wollny | last post: by
5 posts views Thread by TZESENG | last post: by
oll3i
reply views Thread by oll3i | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.