last day (14 days later) » 

8:35 AM
1
Q: java standard serialization order

KonstantinI want to know in which order the attributes of the following example class would be serialized: public class Example implements Serializable { private static final long serialVersionUID = 8845294179690379902L; public int score; public String name; public Date eventDate; } EDIT:...

 
i added the why to my question!
 
@Konstantin Possible case of the XY problem :-)
 
guess youre right with that. ^^ I´m open to alternatives. Although i`m curios how the standard serialization proceeds so i`m staying with my original question.
 
Is this a one-off effort to read the old files or do you need to be able to support both new and old serialized objects going forward? In the former case, you could reconstruct your old class (ensuring the serialVersionUID matches) and extract the necessary data, before re-serializing in a "transport" class you can safely read from later.
 
there clients who stored data through this serialisation and i need to enable them to access this data. Storing via serializable is off the table but restoring from this old serialized files is necessary.
 
8:35 AM
Still interested in solving your underlying problem - so did the original class declare a serialVersionUID?
 
yes they do
 
And did you change that serialVersionUID when the fields in the class changed?
 
no i didnt
 
Finally, what were the changes you made to the class fields? Did you change the type of any fields without changing the name? Or was is simply adding new fields and/or removing old fields?
I think that if you've just added or removed fields, you might get away with trying to deserialize anyway. Missing fields would just be given default values.
 
8:52 AM
ah okay, i`l check it out! Would be nice.
I will have a look at it at first chance,
Thank you for your time and advice! :-)
 
I did a quick test and it looks promising.
Did you remove any fields that you need the value of? That's the only way this will go wrong...
 
no fortunally not!
 

last day (14 days later) »