示例#1
0
 def default(self, obj):
     if isinstance(obj, BaseDocument):
         data = _convert_keys(obj.to_mongo())
         return json_util._json_convert(data)
     elif isinstance(obj, BaseList):
         data = [_convert_keys(d.to_mongo()) for d in obj]
         return json_util._json_convert(data)
     elif isinstance(obj, QuerySet):
         return json_util._json_convert(obj.as_pymongo())
     return FlaskJSONEncoder.default(self, obj)
示例#2
0
 def default(self, o):
     if isinstance(o, Model):
         dikt = {}
         for attr, _ in six.iteritems(o.swagger_types):
             value = getattr(o, attr)
             if value is None and not self.include_nulls:
                 continue
             attr = o.attribute_map[attr]
             dikt[attr] = value
         return dikt
     return FlaskJSONEncoder.default(self, o)
示例#3
0
 def default(self, o):
     if hasattr(o, 'openapi_types'):
         dikt = {}
         for attr, _ in six.iteritems(o.openapi_types):
             value = getattr(o, attr)
             if value is None and not self.include_nulls:
                 continue
             attr = o.attribute_map[attr]
             dikt[attr] = value
         return dikt
     return FlaskJSONEncoder.default(self, o)
 def default(self, o):
     if isinstance(o, Model):
         dikt = {}
         for attr, _ in six.iteritems(o.swagger_types):
             value = getattr(o, attr)
             if value is None and not self.include_nulls:
                 continue
             attr = o.attribute_map[attr]
             dikt[attr] = value
         return dikt
     return FlaskJSONEncoder.default(self, o)
示例#5
0
 def default(self, obj):
     """Override the base method to add support for model objects serialization."""
     if isinstance(obj, Model):
         dikt = {}
         for attr, _ in six.iteritems(obj.openapi_types):
             value = getattr(obj, attr)
             if value is None and not self.include_nulls:
                 continue
             attr = obj.attribute_map[attr]
             dikt[attr] = value
         return dikt
     elif isinstance(obj, datetime.date):
         return to_iso_timestr(obj)
     return FlaskJSONEncoder.default(self, obj)
示例#6
0
 def default(self, o):
     if isinstance(o, Model):
         dikt = {}
         for attr, _ in six.iteritems(o.swagger_types):
             value = getattr(o, attr)
             if value is None and not self.include_nulls:
                 continue
             attr = o.attribute_map[attr]
             dikt[attr] = value
         return dikt
     elif isinstance(o, ObjectId):
         return str(o)
     elif isinstance(o, InsertOneResult) or isinstance(
             o, UpdateResult) or isinstance(o, DeleteResult):
         return json.loads(json_util.dumps(o))
     return FlaskJSONEncoder.default(self, o)
示例#7
0
 def default(self, o):  #pylint: disable=method-hidden
     """
     Defines the encoder for the object provided
     
     :param o: The object to create an encoder for
     """
     if hasattr(o, 'swagger_types') and hasattr(o, 'attribute_map'):
         dikt = {}
         for attr, _ in six.iteritems(o.swagger_types):
             value = getattr(o, attr)
             if value is None and not self.include_nulls:
                 continue
             attr = o.attribute_map[attr]
             dikt[attr] = value
         return dikt
     return FlaskJSONEncoder.default(self, o)
示例#8
0
 def default(self, o):
     if isinstance(o, Model):
         dikt = {}
         for attr, _ in six.iteritems(o.swagger_types):
             value = getattr(o, attr)
             if value is None and not self.include_nulls:
                 continue
             if isinstance(value, Model):
                 value = self.default(value)
             elif isinstance(value, list):
                 for i in range(len(value)):
                     if isinstance(value[i], Model):
                         value[i] = self.default(value[i])
             attr = o.attribute_map[attr]
             dikt[attr] = value
         return dikt
     return FlaskJSONEncoder.default(self, o)
示例#9
0
    def default(self, o):
        if isinstance(o, Model):
            dikt = {}
            for attr, _ in six.iteritems(o.swagger_types):
                value = getattr(o, attr)
                if value is None and not self.include_nulls:
                    continue
                attr = o.attribute_map[attr]
                dikt[attr] = value
            return dikt
        # This should be in the model and the ISD dict that uses this should be
        # using models instead.
        elif isinstance(o, np.ndarray):
            lo = o.tolist()
            if len(lo) == 1:
                return lo[0]
            return lo

        return FlaskJSONEncoder.default(self, o)
示例#10
0
    def default(self, o):
        if isinstance(o, uuid.UUID):
            return str(o)
        elif isinstance(o, (map, set, frozenset)):
            return list(o)
        elif isinstance(o, datetime.datetime):
            if o.tzinfo:
                # eg: '2015-09-25T23:14:42.588601+00:00'
                return o.isoformat('T')
            else:
                # No timezone present - assume UTC.
                # eg: '2015-09-25T23:14:42.588601Z'
                return o.isoformat('T') + 'Z'
        elif isinstance(o, datetime.date):
            return o.isoformat()
        elif isinstance(o, enum.Enum):
            return o.name
        if isinstance(o, Base):
            return sqlalchemy_base_to_dict(o)

        return FlaskJSONEncoder.default(self, o)
示例#11
0
 def default(self, o):
     if o.__class__.__name__ == 'DummyClass':
         return "cool result"
     return FlaskJSONEncoder.default(self, o)
示例#12
0
 def default(self, o):
     if isinstance(o, Base):
         return o.to_dict()
     return FlaskJSONEncoder.default(self, o)
示例#13
0
 def default(self, obj):
     if isinstance(obj, ObjectId):
         return str(obj)
     return FlaskJSONEncoder.default(self, obj)
示例#14
0
 def default(self, o):
     if o.__class__.__name__ == 'DummyClass':
         return "cool result"
     return FlaskJSONEncoder.default(self, o)
示例#15
0
 def default(self, o):
     if isinstance(o, Model):
         return self.encode_model(o)
     return FlaskJSONEncoder.default(self, o)
示例#16
0
 def default(self, o):
     if isinstance(o, FlaskBaseModel):
         return o.to_dict(max_nesting=2)
     return FlaskJSONEncoder.default(self, o)