Makes subclasses of By serializable.

Fixes issue #2670.