def dump(resource, fp, dumper=OdinDumper, **kwargs): """ Dump to a JSON encoded file. :param resource: The root resource to dump to a JSON encoded file. :param dumper: Dumper to use serializing to a string; default is the :py:class:`OdinDumper`. :param fp: The file pointer that represents the output file. """ try: yaml.dump(resource, fp, Dumper=dumper, **kwargs) except ValueError as ex: raise CodecEncodeError(str(ex))
def dumps(resource, cls=OdinEncoder, **kwargs): """ Dump to a JSON encoded string. :param resource: The root resource to dump to a JSON encoded file. :param cls: Encoder to use serializing to a string; default is the :py:class:`OdinEncoder`. :returns: JSON encoded string. """ try: return json.dumps(resource, cls=cls, **kwargs) except ValueError as ex: raise CodecEncodeError(str(ex))