serialversionuid

Why isn't the serialVersionUID automatically generated?

守給你的承諾、 提交于 2019-11-27 16:21:44
问题 Why isn't the serialVersionUID automatically generated? I was running into an issue on an application server where apparently an old class was being cached. 回答1: serialversionuid is not automatically generated because it is dangerous. When serialversionuid is set, it implies that two versions of a class are compatible with respect to serialization. Imagine you have a class called Foo, and it has no serialversionuid (the default), and you serialize an instance of Foo to a file. Later, you add

Finding serialVersionUID of serialized object

狂风中的少年 提交于 2019-11-27 13:43:49
问题 Is there a way to determine the generated serialVersionUID of a serialized Java object? The problem is that I serialized an object without explicitely specifying the serialVersionUID . Now the deserialization process complains about class incompatibilities. However I didn't change the class in a way which would make it incompatible. So I assume that it is enough to specify the serialVersionUID in the class as it is stored in the object data. In order to do this I need to read the

How to deserialize an object persisted in a db now when the object has different serialVersionUID

笑着哭i 提交于 2019-11-27 12:43:37
问题 My client has an oracle data base and an object was persisted as a blob field via objOutStream.writeObject, the object now has a different serialVersionUID (even though the object has no change, maybe different jvm version) and when they try to de-serialize an exception is thrown: java.io.InvalidClassException: CommissionResult; local class incompatible: stream classdesc serialVersionUID = 8452040881660460728, local class serialVersionUID = -5239021592691549158 They didn't assign a fixed

Make Java runtime ignore serialVersionUIDs?

大城市里の小女人 提交于 2019-11-27 01:37:15
I have to work with a large number of compiled Java classes which didn't explicitly specify a serialVersionUID. Because their UIDs were arbitrarily generated by the compiler, many of the classes which need to be serialized and deserialized end up causing exceptions, even though the actual class definitions match up. (This is all expected behavior, of course.) It is impractical for me to go back and fix all of this 3rd-party code. Therefore, my question is: Is there any way to make the Java runtime ignore differences in serialVersionUIDs, and only fail to deserialize when there are actual

explicit serialVersionUID considered harmful?

跟風遠走 提交于 2019-11-27 01:31:22
问题 I am probably risking some downvotes on this. It seems to me that explicitly specifying serialVersionUID for new classes is bad. Consider the two cases of not changing it when layout has it should have been changed and changing it when it should not have. Not changing when it should have been changed occurs almost only when it is explicit. In this case, it results in some very subtle, hard-to-find bugs. Especially during development, when class layout changes often. But if it has not been

What does it mean: The serializable class does not declare a static final serialVersionUID field? [duplicate]

主宰稳场 提交于 2019-11-26 14:07:21
This question already has an answer here: What is a serialVersionUID and why should I use it? 24 answers I have the warning message given in the title. I would like to understand and remove it. I found already some answers on this question but I do not understand these answers because of an overload with technical terms. Is it possible to explain this issue with simple words? P.S. I know what OOP is. I know what is object, class, method, field and instantiation. P.P.S. If somebody needs my code it is here: import java.awt.*; import javax.swing.*; public class HelloWorldSwing extends JFrame {

Why generate long serialVersionUID instead of a simple 1L?

北城以北 提交于 2019-11-26 04:35:34
问题 When class implements Serializable in Eclipse, I have two options: add default serialVersionUID(1L) or generated serialVersionUID(3567653491060394677L) . I think that first one is cooler, but many times I saw people using the second option. Is there any reason to generate long serialVersionUID ? 回答1: As far as I can tell, that would be only for compatibility with previous releases. This would only be useful if you neglected to use a serialVersionUID before, and then made a change that you

What does it mean: The serializable class does not declare a static final serialVersionUID field? [duplicate]

不想你离开。 提交于 2019-11-26 03:48:46
问题 This question already has answers here : What is a serialVersionUID and why should I use it? (25 answers) Closed last year . I have the warning message given in the title. I would like to understand and remove it. I found already some answers on this question but I do not understand these answers because of an overload with technical terms. Is it possible to explain this issue with simple words? P.S. I know what OOP is. I know what is object, class, method, field and instantiation. P.P.S. If

What is a serialVersionUID and why should I use it?

こ雲淡風輕ζ 提交于 2019-11-25 22:53:44
问题 Eclipse issues warnings when a serialVersionUID is missing. The serializable class Foo does not declare a static final serialVersionUID field of type long What is serialVersionUID and why is it important? Please show an example where missing serialVersionUID will cause a problem. 回答1: The docs for java.io.Serializable are probably about as good an explanation as you'll get: The serialization runtime associates with each serializable class a version number, called a serialVersionUID , which is