Support .toBSON() returns non object type

Added support to serialization when .toBSON() does not returns an object.