wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes serializing an ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
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
Rancher

Joined: May 22, 2012
Posts: 866
    
    5
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
Rancher

Joined: May 22, 2012
Posts: 866
    
    5
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: 219

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: 18541
    
    8

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?
 
 
subject: serializing an ArrayList
 
Similar Threads
general methods to different classes
Trying to add a loop
Ending a loop
Need help putting comments in
Creating an Array list