11

What is the need for Action classes to be serializable? When and how does it happen, if at all.

1
  • 1
    I would be interested in the answer. Probably best to ask the struts2 developers on the use mailing list. My guess would be that there are multiple types of output some of which treat the action as the view layer such as is found when using the struts2-json-plugin. If you get a definitive answer and post it I will upvote it, and you may be able to get "self learner" badge.
    – Quaternion
    Jan 25, 2011 at 23:31

3 Answers 3

11

As far as I can tell, it doesn't need to be Serializable, and it was a mistake to make ActionSupport implement that interface.

Here is the best reasoning I have found on the subject (taken from here):

It's very common in web frameworks to use Serializable objects for a couple or reasons, such as being able to preserve state across a server restart and for shipping objects around in a cluster.

With that said, (IMHO) I believe it was a design mistake to have ActionSupport implement Serializable. I don't believe that either of the above really apply to Action objects since they are short-lived. The choice of making Actions Serializable should have been left to the developer and not "forced" by the framework.

0

This question might not be relevant anymore but I thought this might help.
From Sun developer network:

Object serialization is the process of saving an object's state to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time.

So why you might want to serialize your objects? That's when you need to persist their state so you can use them later or in another JVM. The JVM might be on the same machine or over the network on another machine. I think that's the same case for ActionSupport class. If you extend ActionSupport you'll get the chance to serialize your action and send it over the network to be used in another JVM.

-2

i don't know why it must be so. but action classes must extends ActionSupport. and according to http://struts.apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/ActionSupport.html , ActionSupport implements Serializable. so the answer to the when question, it happens all the time :p

2
  • 2
    Not true, actions don't have to extend ActionSupport. They can implement the Action interface or just adhere to convention. Apr 8, 2011 at 15:47
  • 1
    I think he was asking more along the lines of "Does the Struts framework ever actually Serialize ActionSupport", rather than "How often do Struts Action classes implement Serializable". Aug 31, 2011 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.