You can do this by extending ObjectInputStream.
You can do this by extending ObjectInputStream: public class PrintUIDs extends ObjectInputStream { public PrintUIDs(InputStream in) throws IOException { super(in); } @Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { ObjectStreamClass descriptor = super. ReadClassDescriptor(); System.out. Println("name=" + descriptor.getName()); System.out.
Println("serialVersionUID=" + descriptor. GetSerialVersionUID()); return descriptor; } public static void main(String args) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); List list = Arrays. AsList((Object) new Date(), UUID.randomUUID()); oos.
WriteObject(list); oos.close(); InputStream in = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new PrintUIDs(in); ois.readObject(); } } I believe it would be possible to read all the serialized data by replacing the descriptor returned by the method, but I haven't tried it.
There is metadata associated with the serialized bits (a header if you like). You can read the value from the metadata if you know at which position it is (the SerialVersionUID is written there along with other info such as the class name). I think this article might help you: The Java serialization algorithm revealed.
Note that the bits are written "in clear" (unless you encrypted the stream explicitly) so a HEX editor might be all you need to see what is the SerialVersionUID.
There's an easy way to find out serialversionUID of a class- Suppose you have class in which you have forgotten to mention serialversionUID- import java.io. Serializable; public class TestSerializable implements Serializable { } Just do this- serialver -classpath . TestSerializable This prints- static final long serialVersionUID = 5832063776451490808L; serialver is a utility that comes along with JDK.
1 But this only works if you have the old version of class TestSerializable. Lewap's problem is that he doesn't know what the value of serialVersionUID was with an old version of the class of the object he serialized. If he doesn't have to old version of the class anymore, he can't use serialver to find out.
– Jesper Aug 24 '09 at 13:25 that's what version control is for. – james Aug 24 '09 at 13:54.
There is a specified grammar for the serialization of objects: See chapter 6.4 in java.sun.com/javase/6/docs/platform/seri... Using this, you should be able to determine the SerialVersionUID of your serialized object.
That's exactly what you should do - specify your own static final long serialVersionUID. There's a section about it in the docs for Serializable. Unless you've specified a serialVersionUID I don't believe there's an easy way to get it other than deciphering the stream as @WMR suggests.
Note that it should be named serialVersionUID (not: serialversionuid - Java is case-sensitive), and it should be private static final long). – Jesper Aug 24 '09 at 12:28 I agree. But is there a way to read the generated uid from the serialized data?
– lewap Aug 24 '09 at 12:28.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.