serialize the `obj` into file.

        * raise `FormatNotFoundError` on unknown format.
        * raise `SerializeError` on any serialize exceptions.
557079
def dump(self, obj, format=None, *, kwargs={}):
        '''
        
        '''
        return dump(self, obj, format=format, kwargs=kwargs)
1082648
def dumps(self, obj):
        
        out = BytesIO()
        try:
            self.dump(obj, out)
            return out.getvalue()
        finally:
            out.close()
1068968
def serialize(obj, **options):
    '''
    
    '''

    #round-trip this through JSON to avoid OrderedDict types
    # there's probably a more performant way to do this...
    # TODO remove json round-trip when all dataset will use
    # serializers
    return pprint.pformat(
        salt.utils.json.loads(
            salt.utils.json.dumps(obj, _json_module=_json),
            _json_module=_json
        ),
        **options
    )
748721
def serialize(obj):
        
        if isinstance(obj, str_types):
            return obj
        elif hasattr(obj, 'timetuple'):
            return int(time.mktime(obj.timetuple())) * 1000
        elif hasattr(obj, 'item'):
            return obj.item()
        elif hasattr(obj, '__float__'):
            if isinstance(obj, int):
                return int(obj)
            else:
                return float(obj)
        elif hasattr(obj, '__int__'):
            return int(obj)
        else:
            raise LoadError('cannot serialize index of type '
                            + type(obj).__name__)
1095935
def object_to_bytes(obj):
    
    if isinstance(obj, str):
        return bytearray(obj, "UTF-8")
    elif isinstance(obj, bool):
        return bytearray()
    elif isinstance(obj, int):
        return pack("<L", obj)
    elif obj is None:
        return bytearray()
    elif isinstance(obj, bytearray):
        return obj
    else:
        return obj.get_raw()
894105
def serialize(self, obj, method='json', beautify=False, raise_exception=False):
        """"""

        return self.helper.string.serialization.serialize(
            obj=obj, method=method, beautify=beautify, raise_exception=raise_exception)
390920
def serialize(self, obj):
        """"""
        if hasattr(obj, '_jsid'):
            return {'immutable': False, 'value': obj._jsid}
        else:
            obj_json = {'immutable': True}
            try:
                json.dumps(obj)
                obj_json['value'] = obj
            except:
                pass
            if callable(obj):
                guid = str(uuid.uuid4())
                callback_registry[guid] = obj
                obj_json['callback'] = guid
            return obj_json
749170
def json_serialize(obj):
    
    if isinstance(obj, datetime):
        return obj.isoformat()

    if hasattr(obj, 'id'):
        return jsonify(obj.id)

    if hasattr(obj, 'name'):
        return jsonify(obj.name)

    raise TypeError('{0} is not JSON serializable'.format(obj))
42907
public static void serialize(Object object, String file) throws Exception {
        if (object instanceof Serializable) {
            try (FileOutputStream fileOut = new FileOutputStream(file); ObjectOutputStream out =
                    new ObjectOutputStream(fileOut)) {
                out.writeObject(object);
            }
        } else {
            throw new Exception(object.getClass().getName() + " doesn't implements serializable interface");
        }
    }
695326
def dump(self, obj):
        ''''''
        pickle.dump(obj, self._file, protocol=self._protocol)
1064709
def _serialize(self, value, key, obj):
        
        param_values = {}
        for name, attr_tpl in iteritems(self.params):
            attr_name = _tpl(str(attr_tpl))
            if attr_name:
                attribute_value = _get_value(obj, attr_name, default=missing)
                if attribute_value is None:
                    return None
                if attribute_value is not missing:
                    param_values[name] = attribute_value
                else:
                    raise AttributeError(
                        "{attr_name!r} is not a valid "
                        "attribute of {obj!r}".format(attr_name=attr_name, obj=obj)
                    )
            else:
                param_values[name] = attr_tpl
        return url_for(self.endpoint, **param_values)
67525
def obj_to_file(obj, filename, filetype='auto', ndarray_to_list=False, squeeze=True):
    '''

    '''
    # import json
    # with open(filename, mode='w') as f:
    #    json.dump(annotation,f)
    if ndarray_to_list:
        obj = ndarray_to_list_in_structure(obj, squeeze=squeeze)

    # write to yaml
    d = os.path.dirname(os.path.abspath(filename))
    if not os.path.exists(d):
        os.makedirs(d)

    if filetype == 'auto':
        _, ext = os.path.splitext(filename)
        filetype = ext[1:]

    if filetype in ('yaml', 'yml'):
        # import yaml
        from ruamel.yaml import YAML
        yaml = YAML(typ="unsafe")
        with open(filename, 'wt', encoding="utf-8") as f:
            yaml.dump(obj, f)
        # if sys.version_info.major == 2:
        #     with open(filename, 'wb') as f:
        #         yaml.dump(obj, f, encoding="utf-8")
        # else:
        #     with open(filename, "w", encoding="utf-8") as f:
        #         yaml.dump(obj, f)
    elif filetype in ('pickle', 'pkl'):
        f = open(filename, 'wb')
        logger.info("filename " + filename)
        # if sys.version_info[0] < 3: import cPickle as pickle
        # else: import _pickle as pickle
        import pickle
        pickle.dump(obj, f, -1)
        f.close
    elif filetype in ('streamingpicklezip', 'spklz'):
        # this is not working :-(
        import gzip
        import sPickle as pickle
        f = gzip.open(filename, 'wb', compresslevel=1)
        # f = open(filename, 'wb')
        pickle.s_dump(obj, f)
        f.close
    elif filetype in ('picklezip', 'pklz'):
        import gzip
        if sys.version_info[0] < 3: import cPickle as pickle
        else: import _pickle as pickle
        f = gzip.open(filename, 'wb', compresslevel=1)
        # f = open(filename, 'wb')
        pickle.dump(obj, f)
        f.close
    elif filetype in('mat'):

        import scipy.io as sio
        sio.savemat(filename, obj)
    else:
        logger.error('Unknown filetype ' + filetype)
912200
def dump(self, obj):
        
        if self.schema_class:
            obj = self.schema_class().dump(obj).data
        else:
            obj = obj['metadata']
        return super(MARCXMLSerializer, self).dump(obj)
1313865
def write_dict_to_file(file_path, obj):
    
    lines = []
    for key, value in obj.items():
        lines.append(key + ':' + repr(value) + '\n')

    with open(file_path, 'w+') as file:
        file.writelines(lines)

    return None
271746
def serialize(obj):
    
    LOGGER.debug('serialize(%s)', obj)

    if isinstance(obj, datetime.date):
        return simplejson.dumps(obj, default=encoders.as_date)

    elif hasattr(obj, '__dict__'):
        return simplejson.dumps(obj, default=encoders.as_object)

    return simplejson.dumps(obj)
667129
def dump(obj, root_file, proto=0, key=None):
    
    if isinstance(root_file, string_types):
        root_file = root_open(root_file, 'recreate')
        own_file = True
    else:
        own_file = False
    ret = Pickler(root_file, proto).dump(obj, key)
    if own_file:
        root_file.Close()
    return ret
206504
def serialize(obj):
    """"""
    from datetime import datetime, date, time
    if isinstance(obj, date) and not isinstance(obj, datetime):
        obj = datetime.combine(obj, time.min)
    if isinstance(obj, datetime):
        return obj.isoformat()