In my TCP server-client implementation, all of my packets are derived from an abstract base class that implements Serializable. I am converting the class into bytes and send it through the socket, and receiver takes these bytes to deserialize and successfully receive the packet. Because of my lack of knowledge about serialization, I am not sure if this will work because every packet class has a warning like that:
The serializable class CreateObjectPacket does not declare a static final serialVersionUID field of type long
After a bit research, I have found out that JVM uses this UID to ensure the deserialization will be successful (if i am not wrong), so in order to get rid of this warning, i let the eclipse generate default UID but even though Client and Server program have exactly same classes about Packets, the UIDs are different on same classes. Will it cause any problems upon deserialization or should i manually set these UIDs like 1,2,3... ? By the way, I am deserializing the incoming bytes into the super abstract class, Packets, is it also a problem or should i feel free to cast this into the derived Packets ?
EDIT: Lastly, my abstract Packets class has a static methods called fromByteArray for deserialization :
public static Packets fromByteArray(byte[] arr) {
ByteArrayInputStream bis = new ByteArrayInputStream(arr);
ObjectInput in = null;
try {
in = new ObjectInputStream(bis);
Packets o = (Packets) in.readObject();
return o;
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
} finally {
try {
bis.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}