SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-29-2010, 11:34 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #2  
Old 08-29-2010, 11:55 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Here's a good article on serialization (better than I can explain here )... check out the "Serialiation allows for Refactoring" section.
Reply With Quote
  #3  
Old 08-29-2010, 12:19 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #4  
Old 08-29-2010, 12:53 PM
jphipps jphipps is offline
Sage Expert
 
Join Date: Aug 2006
Location: Maryland
Posts: 512
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
Reply With Quote
  #5  
Old 08-29-2010, 12:56 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
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
Tom, I guess in a nutshell, when you create a serializable object, you need to set a serialversionUID. (I normally start at 1). The only time you change that version is if you are making changes to the class that make it incompatible with a previous version. So, if you are only adding a new field to the class, or removing a field, then you should not be modifying the serialversionUID #.

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.
Reply With Quote
  #6  
Old 08-29-2010, 02:14 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
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.
Reply With Quote
  #7  
Old 08-29-2010, 04:39 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #8  
Old 10-17-2010, 11:12 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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;
}
After creating and populating the two lists I serialize the Podcast and save it to disk. I want to make sure that when I read it back and deserialize it that the Lists will also be preserved.

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.
Reply With Quote
  #9  
Old 10-17-2010, 11:18 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
The list will store as Long as the contents are serializable and you cast it back accordingly when reading it.
Reply With Quote
  #10  
Old 10-17-2010, 11:30 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #11  
Old 10-17-2010, 11:44 AM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by tmiranda View Post
But are the Lists stored automatically or do I need to specifically save and restore them?
If they are in a object that you are storing they are saved automatically. If that is what you are asking.
Reply With Quote
  #12  
Old 10-17-2010, 11:52 AM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.