A colleague and I are having a disagreement about a particular scenario.
We have a Serializable
object that has a toString()
method. This toString()
is implemented by invoking Apache's ReflectionToStringBuilder
. Something like this:
public class Foo implements Serializable {
// bunch of instance variables, getters and setters ...
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
}
We have no control over how these objects are passed around. In our particular application, we might pass them around via RMI calls, HTTP POSTs (after writing as a JSon string), via JMS, or via other protocols.
Now, the JSon string case shouldn't matter because it'll be sent in String form so the implementation details of the toString()
method don't matter. But for (some of) the other protocols, we'd expect to serialize the object itself.
Can a method in a Serializable class call a static method and still be (functionally) serializable? It compiles fine, sure -- but can it still be sent across the wire? Will it fail to deserialize if the receiving service does not have the static method's class on its classpath?