Well, the question has a peculiar precondition (as I understand it) - we can select the Serializer
in the serializer and deserializer. Obviously, when I have an instance of V
, my use case is serialization, and the return type does not require V
Thus,
trait Serializer { def save(os: OutputStream): Unit }
it would be enough, and any type can mix it. And do:
def testSer[V](os: OutputStream, v: V): Unit = v match { case s: Serializer => s.save(os) case _ => new ObjectOutputStream(os).writeObject(v) }
And for deserialization, we will either provide a deserializer along with the Ref[V]
string, or rely on a class search through ObjectInputStream
.
source share