I am looking for a way to serialize a class in Java into it's superclass, and then convert it to a byte array and send it over a network.
Here is an example:
class SuperClass {
public int number1;
}
class SubClass extends SuperClass {
public int number2;
}
I don't think it's possible to simply cast an object of SubClass into SuperClass and then serialize it, or am I wrong? Is there some way to do this "conversion" without having to manually copy all the inherited values from a SubClass to a new SuperClass?
EDIT: Well, I realized I was shooting myself in the foot by doing it the way I originally thought of, so what I decided to do was simply serialize SubClass, and use it on both sides of the network connection. It's the simplest thing to do, and I don't have to worry about casting and inheritance.