{"action":"created","issue":{"url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/662","repository_url":"https://api.github.com/repos/mobxjs/mobx-state-tree","labels_url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/662/labels{/name}","comments_url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/662/comments","events_url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/662/events","html_url":"https://github.com/mobxjs/mobx-state-tree/issues/662","id":297450400,"number":662,"title":"custom (de)serialization of Date when snapshotting","user":{"login":"faassen","id":327472,"avatar_url":"https://avatars0.githubusercontent.com/u/327472?v=4","gravatar_id":"","url":"https://api.github.com/users/faassen","html_url":"https://github.com/faassen","followers_url":"https://api.github.com/users/faassen/followers","following_url":"https://api.github.com/users/faassen/following{/other_user}","gists_url":"https://api.github.com/users/faassen/gists{/gist_id}","starred_url":"https://api.github.com/users/faassen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/faassen/subscriptions","organizations_url":"https://api.github.com/users/faassen/orgs","repos_url":"https://api.github.com/users/faassen/repos","events_url":"https://api.github.com/users/faassen/events{/privacy}","received_events_url":"https://api.github.com/users/faassen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-02-15T13:44:19Z","updated_at":"2018-02-22T10:31:28Z","closed_at":"2018-02-22T07:25:20Z","author_association":"CONTRIBUTOR","body":"Date fields are the only types in mobx-state-tree that cannot be unambiguously converted to and from JSON. You chose to use Unix timestamps (as those are apparently in use by a lot of backends), but I'm dealing with a backend that generates ISO 8601 strings instead. I think we can acknowledge that backends handle dates in range of different ways, and that a string representation is not uncommon at all. json-schema for instance also treats date-time as a specific format for strings (a restricted profile of ISO 8601, defined by rfc3339, section 5.6).\r\n\r\nI could either modify the backend to work with timestamps, or create lifecycle hooks to convert ISO 8601 strings into numbers and vice versa, but both approaches are inconvenient; for the backend I'd have to deviate from the normal DateTime API, and for the frontend I'd need to remember to write custom hooks for each model that uses a Date field. There's doesn't appear to be enough information to easily automate such a hook: preProcessSnapshot doesn't have information about the type available, though I haven't explored middleware yet.\r\n\r\nIt would be much more convenient if there were a centralized policy where I could determine how Dates are converted to and from JSON. I realize centralized policies are something to avoid if possible, and it would make snapshots generated through different policies incompatible with each other, but it would seem to be the simplest way to help integrate mobx-state-tree with a backends with a different interpretation of date/time.\r\n"},"comment":{"url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/comments/367638301","html_url":"https://github.com/mobxjs/mobx-state-tree/issues/662#issuecomment-367638301","issue_url":"https://api.github.com/repos/mobxjs/mobx-state-tree/issues/662","id":367638301,"user":{"login":"mweststrate","id":1820292,"avatar_url":"https://avatars0.githubusercontent.com/u/1820292?v=4","gravatar_id":"","url":"https://api.github.com/users/mweststrate","html_url":"https://github.com/mweststrate","followers_url":"https://api.github.com/users/mweststrate/followers","following_url":"https://api.github.com/users/mweststrate/following{/other_user}","gists_url":"https://api.github.com/users/mweststrate/gists{/gist_id}","starred_url":"https://api.github.com/users/mweststrate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mweststrate/subscriptions","organizations_url":"https://api.github.com/users/mweststrate/orgs","repos_url":"https://api.github.com/users/mweststrate/repos","events_url":"https://api.github.com/users/mweststrate/events{/privacy}","received_events_url":"https://api.github.com/users/mweststrate/received_events","type":"User","site_admin":false},"created_at":"2018-02-22T10:31:28Z","updated_at":"2018-02-22T10:31:28Z","author_association":"OWNER","body":"@faassen If I understand the question correctly, this is basically already planned: https://github.com/mobxjs/mobx-state-tree/pull/609/files \r\n\r\nI noticed that there was no actual issue for, so created one, but the feature is WIP and I hope to finish it in the upcoming weeks: https://github.com/mobxjs/mobx-state-tree/issues/673"}}
{"actor":{"display_login":"mweststrate"}}