code: def serialize(self, include_class=True, save_dynamic=False, **kwargs):
          
          if getattr(self, '_getting_serialized', False):
              raise utils.SelfReferenceError('Object contains unserializable '
                                             'self reference')
          self._getting_serialized = True
          try:
              kwargs.update({
                  'include_class': include_class,
                  'save_dynamic': save_dynamic
              })
              if save_dynamic:
                  prop_source = self._props
              else:
                  prop_source = self._backend
              data = (
                  (key, self._props[key].serialize(getattr(self, key), **kwargs))
                  for key in prop_source
              )
              json_dict = {k: v for k, v in data if v is not None}
              if include_class:
                  json_dict.update({'__class__': self.__class__.__name__})
              return json_dict
          finally:
              self._getting_serialized = False
docs: Serializes a **HasProperties** instance to dictionary
  
          This uses the Property serializers to serialize all Property values
          to a JSON-compatible dictionary. Properties that are undefined are
          not included. If the **HasProperties** instance contains a reference
          to itself, a :code:`properties.SelfReferenceError` will be raised.
  
          **Parameters**:
  
          * **include_class** - If True (the default), the name of the class
            will also be saved to the serialized dictionary under key
            :code:`'__class__'`
          * **save_dynamic** - If True, dynamic properties are written to
            the serialized dict (default: False).
          * Any other keyword arguments will be passed through to the Property
            serializers.