Results 1 to 13 of 13
Thread: Serialization
- 05-17-2011, 04:12 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
- 05-17-2011, 04:33 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
My understanding of serialization is that it will serialize all object references(assuming they are also serializable), and it will create a "web". I do not believe there is a limit to how much will be serialized either.
The best way to check this would be to simply make a few small classes and then a final class which has one instance variable for each other class, then in main, instantiate all classes and save the final class(which holds references to the others).
Create a toString which prints the info of everything in the class, serialize t to disk, deserialize it, then print the object and observe what happens.
Finally, consider reading this article and see if it helps you out: Discover the secrets of the Java Serialization API
By googling "serialize java tutorial" or "serialize java information" you should get lots of hits with plenty of details.
- 05-17-2011, 01:54 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
Thanks. I did actually read one of the links you sent beforehand but it didn't state if there were any limits on number of objects or "hierarchy" of objects.
- 05-17-2011, 09:29 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
I'm just wondering how I can use serialization while maintaining a MVC structure. I'm thinking of making the source class static as well as a separate serializer class static, with no associations. Then accessing the class through the global variables. Is this a reasonable way to do this?
- 05-17-2011, 09:36 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,395
- Blog Entries
- 7
- Rep Power
- 17
- 05-17-2011, 09:48 PM #6
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
If I made class B implement the serializer class and then tried to serialize a class a A object via a class B object, I would need to cast object A as type class B right?!? and they would need to have the same properties in each class to be castable from one to the other..unless they're declared transient?
- 05-17-2011, 09:56 PM #7
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
Sorry, i'm going to rephrase my previous message:
If I made class B implement the serializer class and then tried to serialize a class A object via a class B static method, I would need to cast object A as type class first right? Would this work if I gave them the same (non transient) properties to both classes?
- 05-18-2011, 09:47 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,395
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-18-2011, 09:53 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
If class A is not a subclass (ie extends) class B then you cannot cast from one to the other.
Class B implementing Serializable will have no effect on either a static method in class B nor on any classes class B happens to use (other than as attributes of a Class B object).
If you want to be able to serialise class A then you will have to make A implement Serializable.
- 05-18-2011, 11:28 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
And why is .NET at all relevant?The .NET Framework features two serializing technologies:
It isn't...so I can only assume this is a bit of spam to advertise your sig link.
- 05-18-2011, 01:03 PM #11
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
Thanks for your comments!
JosAH, I'm trying to achieve decoupling between the controller and model, hence why I'm trying to use two different classes.
Tolls, I hoped that would not be a rule about casting objects. Kind of blows my implementation out of the water :\
Am I right in saying that serialization is not strictly compatible with an MVC framework therefore, as I would have to implement a serializer in the controller class? Is there any way I can implement serialization and still achieve decoupling ?
- 05-18-2011, 01:36 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
What are you trying to do?
Serialisation requires you to possess the classes that have been serialised, both at the poitn where they're serialised and the point where they're deserialised. So of course source and target are going to be closely coupled.
- 05-18-2011, 01:49 PM #13
Member
- Join Date
- Apr 2011
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Serialization
By sunde887 in forum New To JavaReplies: 4Last Post: 02-15-2011, 10:47 PM -
serialization
By elsa14290 in forum Advanced JavaReplies: 1Last Post: 02-06-2010, 04:03 PM -
Serialization
By thayalan in forum Advanced JavaReplies: 4Last Post: 08-03-2009, 10:22 PM -
about serialization
By bishnu in forum New To JavaReplies: 0Last Post: 12-19-2008, 09:13 AM -
What is Serialization and de-serialization in Java
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks