How do I globally control to/from json and override datetime to milliseconds #387
Unanswered
stpham-clgx
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to solve these 2 issues:
1- I want to convert all key name to Camelcase when calling to_json. The only way to do this is to include letter_case for all of my data classes. I have lot of data nested data classes. It would be nice to pass in letter_case to override in to_json method
2- I want to serialize all of my datetime attributes to milliseconds and don't want to specify config for each attributes. I like to pass in my own ExtendedEncoder to to_json method
I need this transformation because I need to share json between Java and Python.
Java is Camelcase and Python is snake case!
My current work around:
object = SomeNextedDataClass()
d = camel_dist(object.to_dist())
json.dumps(d, cls=MyExtendedEncoder)
This achieve what I am looking for, but wish that I can simply do this:
object.to_json(letter_case = Letter.CAMEL, cls=MyExtendedEncoder)
Beta Was this translation helpful? Give feedback.
All reactions