The javadocs of the defaultWriteObject method explain why you're getting this exception - you're not serializing the current object.
I think what you may mean to call is "os.writeObject(new
Test())". Then you need to implement the writeObject method as explained in the javadocs for Serializable.