code: def to_json(value, **kwargs):
          
          if isinstance(value, HasProperties):
              return value.serialize(**kwargs)
          try:
              return json.loads(json.dumps(value))
          except TypeError:
              raise TypeError(
                  "Cannot convert type {} to JSON without calling 'serialize' "
                  "on an instance of Instance Property and registering a custom "
                  "serializer".format(value.__class__.__name__)
              )
docs: Convert instance to JSON