-
Notifications
You must be signed in to change notification settings - Fork 339
fix(fcm): String representation in Message class #350
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
Conversation
Sample output:
|
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.
One suggestion added.
This also brings up the question whether we should support __str__
on all public classes in this module (e.g. AndroidConfig, Notification etc). But Message
is probably enough to begin with. After all, other objects are never used by themselves -- they are always part of a Message
.
Also please add a test case.
firebase_admin/_messaging_utils.py
Outdated
@@ -57,6 +57,9 @@ def __init__(self, data=None, notification=None, android=None, webpush=None, apn | |||
self.topic = topic | |||
self.condition = condition | |||
|
|||
def __str__(self): | |||
return json.dumps(MessageEncoder().default(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.
Would this work?
json.dumps(self, cls=MessageEncoder)
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.
Yes! Thank you.
Will update with test cases soon.
|
416f784
to
588a1fb
Compare
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.
LGTM :+1
Discussion
Message
classMessageEncoder
to convertMessage
objects to valid JSON stringsTesting
API Changes
Resolves: #349
RELEASE NOTE:
Message
class now implements the__str__()
contract which can be used to obtain a string representation of aMessage
instance.