def serialize(collection, encryption_service, public_key):
    """
    Serializes a collection if the encryption service is on.
    Returns the collection as a list.
    :param collection: a collection of numbers or encrypted numbers if the encryption_service is on.
    :param encryption_service: the encryption service.
    :param public_key: the public key for serializing numbers.
    :return: A list with the content serialized if the encryption service is on.
    """
    encryption_service.set_public_key(public_key)
    collection = collection.tolist()
    return encryption_service.get_serialized_collection(collection
        ) if encryption_service.is_active else collection
