Enforcing that the object is of a type that can be encoded and throwing an exception otherwise instead of failing silently.