Fix BSON custom serialization of const classes and fix the corresponding unit test. See #653.