Write object into the stream
        :param val:
        :param outstream:

def _write_object(self, val, outstream):
        '''
        Write object into the stream
        :param val:
        :param outstream:
        '''
        # first attempt using an existing custom serializer
        serializer = self.__lookup_serializer(getattr(val, '__class__'))
        if serializer is not None:
            serializer.serialize(self, val, outstream)
            return
        
        fields = self._fetch_obj_fields(val)
        validfields = [];
        encodedfields = []
        length = 0;
        for f in fields:
            encoded = self._encode_field_name(val, f)
            if encoded:
                encodedfields.append(encoded)
                validfields.append(f)
                length += 1;
        self.write_object_start(length, outstream)
        count = 0;
        if length > 0:
            mappedname = encodedfields[0]
            if mappedname is not None:
                count += 1
                self.write_object_field(mappedname, getattr(val, validfields[0]), outstream)
            idx = 1
            while idx < length:      
                name = validfields[idx]
                mappedname = encodedfields[idx]
                if mappedname is not None:
                    value = getattr(val, name)
                    if count > 0:
                        self.write_object_field_separator(mappedname, value, outstream)
                    self.write_object_field(mappedname, value, outstream)
                    count += 1
                idx += 1
        self.write_object_end(length, outstream)