def METHOD_NAME(config: dict, logger: Logger) -> bytes:
    """Serialize a dict to JSON if possible or Pickle otherwise"""
    as_json_text = check_round_trip(config, logger)
    if as_json_text and SHOULD_SAVE_AS_JSON:
        assert isinstance(as_json_text, bytes)
        return as_json_text
    else:
        return pickle.dumps(config, protocol=2)