-
Notifications
You must be signed in to change notification settings - Fork 11
Update model to_json methods to use Pydantic v2 model_dump_json #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,8 +29,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -95,8 +94,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -164,8 +162,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -232,8 +229,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -298,8 +294,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -376,8 +371,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -545,8 +539,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -619,8 +612,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -695,8 +687,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -761,8 +752,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
@@ -844,8 +834,7 @@ def to_str(self) -> str: | |||||
|
|
||||||
| def to_json(self) -> str: | ||||||
| """Returns the JSON representation of the model using alias""" | ||||||
| # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead | ||||||
| return json.dumps(self.to_dict()) | ||||||
| return self.model_dump_json(by_alias=True, exclude_unset=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.
Suggested change
|
||||||
|
|
||||||
| @classmethod | ||||||
| def from_json(cls, json_str: str) -> Self: | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'exclude_unset=True' in 'to_json()' creates an inconsistency with 'to_dict()', which uses 'exclude_none=True'. For example, if a field is explicitly initialized to 'None', 'to_dict()' will exclude it, whereas 'model_dump_json(exclude_unset=True)' will include it. To ensure consistent serialization behavior between 'to_dict()' and 'to_json()', use 'exclude_none=True' instead.