Replacement for deprecated to_dict_recursive?
Lawouach opened this issue · 7 comments
Is your feature request related to a problem? Please describe.
It seems the to_dict_recursive·
method is now deprecated by #1101 without much explanation. Is there a replacement for it that is public and stable?
Describe the solution you'd like
I need to record the session in our db and it was easy store as a jsonb payload.
Describe alternatives you've considered
Well I'm looking for one :p
I guess I could simply copy the code but that feels a bad move.
Additional context
No response
Hi @Lawouach, we might have been too overzealous with deprecation here. We'll get back to you with either a replacement or undeprecation of to_dict_recursive
No worries @pakrym-stripe. Thanks for getting back to me so rapidly :)
Hi @Lawouach,
Can you use json.dumps(obj)
to get JSON (or json.loads(json.dumps(obj))
if you really need a dict)? I've convinced myself this behaves equivalently to .to_dict_recursive
1
You can also try obj.last_response.body
(json string) or obj.last_response.body
(dict) if you are working with top level responses to API requests, although this won't work for webhook payloads or subobjects.
Footnotes
-
(except for the obscure edge case where you are mutating the StripeObject and set a field as something non-json that causes
json.dumps
to crash, like a datetime. ↩
Hi @richardm-stripe I would be happy to use such an approach. I'll see if I can try it soon.
@Lawouach, were you able to try the proposed solution?
I didn't get the chance but feel free to close for now and I'll reopen if that doesn't work. But I trust the research made by @richardm-stripe
Closing!
For anyone else reading this: please feel free to reopen also and detail if you have a use case for .to_dict_recursive
. json.dumps(obj)
is appropriate here, but that might not be universally true.