def make_serializable(data):
if is_serializable(data):<EOL><INDENT>return data<EOL><DEDENT>try:<EOL><INDENT>return data.tolist()<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>except Exception as e:<EOL><INDENT>logger.debug('<STR_LIT>'.format(type(e).__name__, e, data))<EOL><DEDENT>if isinstance(data, dict):<EOL><INDENT>return {key: make_serializable(value) for key, value in data.items()}<EOL><DEDENT>try:<EOL><INDENT>return [make_serializable(element) for element in data]<EOL><DEDENT>except TypeError:  <EOL><INDENT>pass<EOL><DEDENT>except Exception:<EOL><INDENT>logger.debug('<STR_LIT>'.format(data))<EOL><DEDENT>return str(data)<EOL>
Ensure data is serializable.