![]() |
|
SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
![]() |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
||||
|
||||
Serialization
I'm creating a plugin that stores serialized objects in a file. I notice that when I change the class the objects previously serialized and written to disk can no longer be "de-serialized".
What can I change in the class that will NOT cause the previously serialized objects to become invalid? I suppose my bigger question is how do you "future proof" the plugin so that when you change things in the class the objects already stored on disk can still be read? (I don't want to wipe out the user's database.) Thanks, Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#2
|
||||
|
||||
Here's a good article on serialization (better than I can explain here
![]()
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#3
|
||||
|
||||
Sean,
I get the gist, but the article is short on details. It says you can read and deserialize the objects by running serialver on the original class and altering the serialVersionUID on the updated class, but nothing more. I did some Googling on "java refactor serialized class" but that didn't get me anything very useful. I don't mind reading, but I don't know what I'm looking for ![]() I was hoping for a way I could tell what version of the class was serialized so I could convert it to the new class as necessary. Thanks for any pointers, Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#4
|
|||
|
|||
Hello,
Found this article that goes into some detail on the serialVersionUID and also has a link to a guide on Oracle(Sun) web site on what changes can be made to a serializable object that can be deserialized once it has been changed. http://www.javapractices.com/topic/TopicAction.do?Id=45 In the code that I use a serializable object, I try to keep it as static as possible, any change in the object will cause the hash on that object to change and make it not compatible. So if you are storing objects for later use, I would probably store the data you need in the object, but put any code/logic outside of it that would just interact with the serialized object in a separate class.. Thanks, Jeff |
#5
|
||||
|
||||
Quote:
Personally, I don't like to use the java serialization for any long term storage, but I do use it quite a bit for short term persistence. For longer term storage, you might want to look at either manually storing your objects using xml (or some other format) or using a custom serializer, which gives you more control over how the object is saved and loaded.
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#6
|
|||
|
|||
For your case I agree with Sean you might want to look at something else. I use serialization for my objects that I store simply because they are a replica of another SQL database so rebuilding the datafile on changes is always possible and easy. I simply use it so I don't have to rebuild the objects on each load.
|
#7
|
||||
|
||||
Jeff, Sean, Skye,
Thanks for the insight. I probably would have done things differently if I knew more about Java Serialization when I started. For now I guess I'll worry about "future-proofing" at another time. By the time I get this plugin working I'll probably have to start over (again) to make it compatible with Sage version 8 and by then Java 7 will have a way to get around the issue ![]() Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#8
|
||||
|
||||
If I have a Serializable class that contains a List<>. When the class is serialized will the contents of the List be serialized or do I need a custom serializer for that?
The class looks like this: Code:
public class Podcast implements Serializable { private List<UnrecordedEpisode> episodesOnServer = null; private List<Episode> episodesEverRecorded = null; } Thanks, Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#9
|
|||
|
|||
The list will store as Long as the contents are serializable and you cast it back accordingly when reading it.
|
#10
|
||||
|
||||
But are the Lists stored automatically or do I need to specifically save and restore them?
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#11
|
|||
|
|||
If they are in a object that you are storing they are saved automatically. If that is what you are asking.
|
#12
|
||||
|
||||
Yes, thanks.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|