-
Notifications
You must be signed in to change notification settings - Fork 34
Custom Distinct DateTime type breaks serialization of object to string? #38
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
Comments
I'm an idiot, my bad. To myself and others that potentially run into this issue: |
To prevent this from happening in the future the mutable string could be changed into a |
@PhilippMDoerner I am glad you figured it out. The readme even has a section for datetime: https://github.com/treeform/jsony#proc-parsehook-can-be-used-to-do-anything I have spent a lot of time dealing with time in web applications I have even written my own calendar + timezone library https://github.com/treeform/chrono . I highly recommend using float64 seconds sense 1970 - the unix epoch to transfer times. |
Heyho @treeform The necessity to stick with another DateTime type lies within where my database comes from: I already have one and it was generated through Django's ORM (in general, I'm re-implementing an already existing backend of a sideproject of mine for learning purposes). Django sets datetime columns up so that they store datetime as a string with the pattern I'll definitely keep moving to unix timestamps in mind, since it'd make things simpler, but I didn't want to include a database migration in this phase of the project. |
Your reasoning for sticking |
Heyho!
I'm using jsony in a web-application. There I want to use it to serialize an de-serialize JSON strings into objects, specifically of norm-objects (an ORM) which is filled with data coming from a database.
Due to the way norm handles Datetimes, I had to implement a custom DateTime type that borrows/reimplements DateTime's functionality, that appears to cause some problems.
What I found is that, when doing so, jsony drops part of the serialization string silently, without an error message.
Here is a minimum example that demonstrates the issue when I run it on "https://play.nim-lang.org/".
This should print out
{"nameA": "The name of A", "datetimeA": "<FORMATTED CURRENT DATETIME>"}
.Instead it prints out
<FORMATTED CURRENT DATETIME>}
.It drops the parts of the string that come before
DjangoDateTime
is converted into a string.I am not quite sure what is happening here, though I can only assume that it's
DjangoDateTime
causing this. How, I'm not sure.The text was updated successfully, but these errors were encountered: