File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes serializing an ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "serializing an ArrayList" Watch "serializing an ArrayList" New topic
Author

serializing an ArrayList

Ricardo Soares
Greenhorn

Joined: Nov 27, 2012
Posts: 9
Hello everyone, here is my problem:

i have the following classes:







each time i create an instance of Event it receives a date and is then added to the arraylists events

I have another class that does the serialization to and from xml

when i deserialize the xml it restores all the elements of the events arraylist but each event has its date ( day month and year ) with values 0

is there anything i need to do in order to make my serialization save the variables from the date class ?

thanks in advance
Ivan Jozsef Balazs
Ranch Hand

Joined: May 22, 2012
Posts: 380
You did not post the relevant part of your Date class.
Hopefully the data members are not transient!
Ricardo Soares
Greenhorn

Joined: Nov 27, 2012
Posts: 9
no they are not transient

Ivan Jozsef Balazs
Ranch Hand

Joined: May 22, 2012
Posts: 380
That seems to be ok. How do you fill that List?
Ricardo Soares
Greenhorn

Joined: Nov 27, 2012
Posts: 9



class helper is a class with methods to create, edit, remove, etc
Ishan Pandya
Ranch Hand

Joined: Feb 06, 2012
Posts: 129

I am not Sure but if your are building a manual "Date" class which implements Serializable and has Constructor of your choice then please do change its name from Date to MyDate or anything you like..and make the respective changes every where in your code.
I think it would be because if you use "java.util.*" as an import statement it may take the inbuilt Date class.
Do the change and post what happens after that..


OCPJP
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16482
    
    2

Ricardo Soares wrote:I have another class that does the serialization to and from xml

when i deserialize the xml it restores all the elements of the events arraylist but each event has its date ( day month and year ) with values 0

is there anything i need to do in order to make my serialization save the variables from the date class ?


Well, yes there is. But since we don't know how your deserializing works, it's hard to say much about exactly what you would have to do. I can say that just declaring classes as Serializable doesn't have any effect on how you get your data out of an XML document -- at least, probably not. How about showing us how you deserialize from XML?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: serializing an ArrayList
 
Similar Threads
Creating an Array list
Ending a loop
Need help putting comments in
Trying to add a loop
general methods to different classes