When using value objects, I am aware that they have to implement Serializable.
1) Do you have to create any other methods on the object to write the stream, or will the container do this automatically?
2) Why do they have to implement serializable?
Cheers..
-
Serialization coding for value objects (3 messages)
- Posted by: Nick Stephens
- Posted on: August 09 2001 06:31 EDT
Threaded Messages (3)
- Serialization coding for value objects by Race Condition on August 09 2001 09:28 EDT
- Serialization coding for value objects by Adnan Rafiq on August 09 2001 11:22 EDT
- Serialization coding for value objects by Tony Brookes on August 09 2001 22:26 EDT
-
Serialization coding for value objects[ Go to top ]
- Posted by: Race Condition
- Posted on: August 09 2001 09:28 EDT
- in response to Nick Stephens
1) Automagic.
2) I don't know. I just follow the cookbook. -
Serialization coding for value objects[ Go to top ]
- Posted by: Adnan Rafiq
- Posted on: August 09 2001 11:22 EDT
- in response to Nick Stephens
The answer to your second question lies in RMI. The value objects are passed back and forth between different tiers (presentation/servlet and application/EJB). In J2EE, the tiers could potentially reside in multiple JVMs. RMI allows objects to communicate in memory, across JVMs. It also requires that all objects that are passed as parameters be serializable. Hence, the need for the value objects to implement Serializable.
-
Serialization coding for value objects[ Go to top ]
- Posted by: Tony Brookes
- Posted on: August 09 2001 22:26 EDT
- in response to Nick Stephens
1) You don't HAVE to do anything, but if your object is complex, then be aware that reflection will be used to serialize the object, which will be slow.
Speed it up by over-riding the readObject and writeObject methods and simply spit the objects you contain down the stream you are provided in a given order. Then read them back out the other end in the corresponding order. If you have a complex object you will be amazed at how much faster your machine goes!
2) Serializable is used to tell the VM that it is OK to pass this object outside your virtual machine. It is a marker interface only, in the same manner as Cloneable.
Chz
Tony