-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add custom JSONEncoder for model serialization #19595
Conversation
e4e71cd
to
6ec7641
Compare
return 'P' + date + time | ||
|
||
|
||
class UTC(datetime.tzinfo): |
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.
/azp run python - core - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
@mccoyp _utils.py has been moved into utils folder. |
"timedelta": timedelta(1), | ||
"date": date(2021, 5, 12), | ||
"datetime": isodate.parse_datetime('2012-02-24T00:53:52.780Z'), |
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.
When the conversation starts regarding deserialization - we will want to make sure we support weird .NET timestamps (with extra decimal places). When that conversation happens - what we do to serialize round-tripped values will be important as well.
import datetime | ||
from json import JSONEncoder | ||
|
||
from .utils._utils import _FixedOffset |
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.
Do we really need to import a private type from a private submodule?
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.
I think we should rename _FixedOffset to FixedOffset. But not sure if it is worth...
/azp run python - autorest - pr |
Azure Pipelines successfully started running 1 pipeline(s). |
# Remove trailing zeros | ||
seconds_string = seconds_string.rstrip("0") | ||
except AttributeError: # int.is_integer() raises on Python 2.7 | ||
seconds_string = "{:02}".format(seconds) |
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.
Does this still need int()
around seconds?
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.
I wouldn't think so, since this AttributeError should only come up if seconds
is an integer. seconds.is_integer()
works when seconds
is a float on 2.7. 3.6, and 3.9 when I test locally
|
||
|
||
NULL = _Null() | ||
""" | ||
A falsy sentinel object which is supposed to be used to specify attributes | ||
with no data. This gets serialized to `null` on the wire. | ||
""" | ||
|
||
|
||
def timedelta_as_isostr(value): |
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.
This is currently part of the public API - which I don't think it should be, at least to start with.
Can we make it private?
/azp run python - core - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run python - core - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run python - core - ci |
Azure Pipelines successfully started running 1 pipeline(s). |
ARM ID annotations for Postgres (Azure#19595)
This adds a custom JSONEncoder that can serialize
datetime
objects (date
s,time
s,datetime
s, andtimedelta
s) in UTC ISO 8601 format, as well asbytes
andbytearray
s in base64 strings.