Hi, I'll be up front and say I'm a CS student who is trying to complete a homework assignment.
I have been tasked to serialize an object (named Library) and saving to a file on disk.
Library contains only one object- HashMap<Double, Book> where Book is another class in the project, and the Double value consists of the book's ISBN number
On that note, the Book object consists of two primitive int values, an object of type "Title", and an ArrayList<Borrower> where Borrower is another class in the project.
Title consists of two
String objects and a double value
Borrower consists of one String object and two Calendar objects
Library is a singleton class
I have added the import statement and "implements Serializable" in all of these classes, but nothing else.
I plan to try make the serialization safer after I successfully serialize the Library class using the default method.
Here's the issue: I'm having a problem serializing the Library class. When I serialize this class, the file created only contains one short line which basically identifies the Library object as...who knows (I think- it's hard to read serialized data in NotePad). When I serialize only the HashMap object, however, I am able to almost perfectly duplicate the Library to disk. I thought all was well until I realized the information in the Book class' ArrayList<Borrower> object was not persisting.
So there's something else I need to learn still! I have considered that the problem I'm having is that the generic or default serialized form of the Library and Book classes do not properly package the object, but I don't know how to build a custom serialization object. I have the text "Effective Java", J. Bloch, but it isn't very much help on this subject. Bloch seems to assume that the reader will know how to do this already. Other readers might...I don't!
Here's my methods so far:
Is there something simple concerning HashMaps and ArrayLists that I'm missing here?
Thanks for any thoughts / direction offered on this.
-Will