File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Serializable Action Forms?  Why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Serializable Action Forms?  Why?" Watch "Serializable Action Forms?  Why?" New topic

Serializable Action Forms? Why?

Charles McGuire
Ranch Hand

Joined: Jan 18, 2005
Posts: 99
The Struts documentation ( says we should serialize ActionForms:

Because ActionForms are JavaBeans, subclasses should also implement Serializable, as required by the JavaBean specification. Some containers require that an object meet all JavaBean requirements in order to use the introspection API upon which ActionForms rely." (16Oct2004)


The ActionForm class already implements Are not the subclasses extended from this class automatically serialized by inheritance? In other words, why implement serializable again?

There's no place like
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Wow. Great question. I never noticed it before and it's right there in the ActionForm's javadoc.

Yes, if ActionForm is Serializable its subclasses implement Serializable.

Speople specify "implements Serializable" in bean subclasses as a gentle reminder. It's still weird that the Javadoc says that. Maybe it was intended as a reminder any non-Serializable class variable should be declared transient.

A good workman is known by his tools.
Charles McGuire
Ranch Hand

Joined: Jan 18, 2005
Posts: 99
Thank you for acknowledging the question. The date on the JavaDoc is relatively recent, too. It is weird, and no one has a good answer; everyone I ask seems equally stumped, even my Struts instructor.

Oh, the humanity!

Jason Menard

Joined: Nov 09, 2000
Posts: 6450
I can tell you that awhile ago a version of Tomcat I used threw a stack trace on shutdown and startup (only after the first time the app had been started) complaining that some of my ActionForm classes, which I had kept in session scope, were not serializable. I believe this had something to do with the way Tomcat tried to save and restore sessions; just a guess, I didn't really look into it too hard. Implementing serializable took care of the situation.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33117

I took that to mean that the subclass should observe the contract of Serializable, not just implement the interface. For example, all of the fields must be Serializable.

Personally, I like to implement Serializable explicitly as a reminder.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Serializable Action Forms? Why?
jQuery in Action, 3rd edition