-
Notifications
You must be signed in to change notification settings - Fork 62
Closed
Description
Design:
Step 1: AzureJSONEncoder
- Restart back from azure-core AzureJSONEncode (so we can migrate it back to azure-core later)
- Add two kwargs
exclude_readonlyandexclude_none
This means this should look like this:
class AzureJSONEncoder(JSONEncoder):
def __init__(self, *args, *, exclude_readonly: bool = False, exclude_none: bool = False, **kwargs):
super().__init__(*args, **kwargs)
self.exclude_readonly = exclude_readonly
self.exclude_none = exclude_noneThis design allows to call json.dumps this way:
json.dumps(my_model, exclude_readonly=True, exclude_none=True, cls=AzureJSONEncoder)This works since json.dumps inject kwargs into the constructor of cls, so we have access to custom kwargs.
Step 2:
- Add a
as_dictin all model that is literally:
def as_dict(self, *, exclude_readonly: bool = False, exclude_none: bool = False):
return json.dumps(self, exclude_readonly=exclude_readonly, exclude_none=exclude_none, cls=AzureJSONEncoder)Step 3:
- Update our operation template to call
as_dict(exclude_readonly=True, exclude_none=True)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels