def to_serializable(self, use_bytes=False, bytes_type=bytes):
        """Convert a :class:`SampleSet` to a serializable object.

        Note that the contents of the :attr:`.SampleSet.info` field are assumed
        to be serializable.

        Args:
            use_bytes (bool, optional, default=False):
                If True, a compact representation representing the biases as bytes is used.

            bytes_type (class, optional, default=bytes):
                This class will be used to wrap the bytes objects in the
                serialization if `use_bytes` is true. Useful for when using
                Python 2 and using BSON encoding, which will not accept the raw
                `bytes` type, so `bson.Binary` can be used instead.

        Returns:
            dict: Object that can be serialized.

        Examples:
            This example encodes using JSON.

            >>> import dimod
            >>> import json
            ...
            >>> samples = dimod.SampleSet.from_samples([-1, 1, -1], dimod.SPIN, energy=-.5)
            >>> s = json.dumps(samples.to_serializable())

        See also:
            :meth:`~.SampleSet.from_serializable`

        """
        schema_version = "2.0.0"

        record = {name: array2bytes(vector)
                  for name, vector in self.data_vectors.items()}
        record['sample'] = array2bytes(np.packbits(self.record.sample > 0))

        if not use_bytes:
            for name in record:
                record[name] = base64.b64encode(record[name]).decode("UTF-8")

        return {"basetype": "SampleSet",
                "type": type(self).__name__,
                "record": record,
                "sample_dtype": str(self.record.sample.dtype),  # need this to unpack
                "sample_shape": self.record.sample.shape,  # need this to unpack
                "variable_type": self.vartype.name,
                "info": self.info,
                "version": {"dimod": __version__,
                            "sampleset_schema": schema_version},
                "variable_labels": list(self.variables),
                "use_bytes": bool(use_bytes)}