{"action":"created","issue":{"url":"https://api.github.com/repos/sampsyo/confit/issues/13","labels_url":"https://api.github.com/repos/sampsyo/confit/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/sampsyo/confit/issues/13/comments","events_url":"https://api.github.com/repos/sampsyo/confit/issues/13/events","html_url":"https://github.com/sampsyo/confit/issues/13","id":64987459,"number":13,"title":"de/serialization and validation","user":{"login":"thejohnfreeman","id":1133852,"avatar_url":"https://avatars.githubusercontent.com/u/1133852?v=3","gravatar_id":"","url":"https://api.github.com/users/thejohnfreeman","html_url":"https://github.com/thejohnfreeman","followers_url":"https://api.github.com/users/thejohnfreeman/followers","following_url":"https://api.github.com/users/thejohnfreeman/following{/other_user}","gists_url":"https://api.github.com/users/thejohnfreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/thejohnfreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejohnfreeman/subscriptions","organizations_url":"https://api.github.com/users/thejohnfreeman/orgs","repos_url":"https://api.github.com/users/thejohnfreeman/repos","events_url":"https://api.github.com/users/thejohnfreeman/events{/privacy}","received_events_url":"https://api.github.com/users/thejohnfreeman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-28T21:04:35Z","updated_at":"2015-03-29T21:07:09Z","closed_at":null,"body":"Each type needs a deserializer. Most types have a constructor (e.g. `int`, `float`, `bool`), and that is enough. Clients should be able to provide alternatives, though, because a deserializer also encompasses validation.\r\n\r\nSome clients may want to serialize configurations. Most types have a `__str__` method, and that is enough. Clients should be able to provide alternatives, though, in case `__str__` does not exist or match the deserializer.\r\n\r\nI saw the issue on Confit templates, and the idea is very similar. Going back to my assumptions (#7), though, I think it needs to be mandatory, not optional. A simple dict will be enough to define both types and defaults, however, so it should not be burdensome."},"comment":{"url":"https://api.github.com/repos/sampsyo/confit/issues/comments/87477224","html_url":"https://github.com/sampsyo/confit/issues/13#issuecomment-87477224","issue_url":"https://api.github.com/repos/sampsyo/confit/issues/13","id":87477224,"user":{"login":"sampsyo","id":188033,"avatar_url":"https://avatars.githubusercontent.com/u/188033?v=3","gravatar_id":"","url":"https://api.github.com/users/sampsyo","html_url":"https://github.com/sampsyo","followers_url":"https://api.github.com/users/sampsyo/followers","following_url":"https://api.github.com/users/sampsyo/following{/other_user}","gists_url":"https://api.github.com/users/sampsyo/gists{/gist_id}","starred_url":"https://api.github.com/users/sampsyo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sampsyo/subscriptions","organizations_url":"https://api.github.com/users/sampsyo/orgs","repos_url":"https://api.github.com/users/sampsyo/repos","events_url":"https://api.github.com/users/sampsyo/events{/privacy}","received_events_url":"https://api.github.com/users/sampsyo/received_events","type":"User","site_admin":false},"created_at":"2015-03-29T21:07:09Z","updated_at":"2015-03-29T21:07:09Z","body":"Indeed. In Confit, you can write `view.get(int)` to ensure that you get an int back, but you can also write `view.get()` to get whatever unsanitized data the YAML gives us. (I don't have a particular attachment to that unsanitized mode; it's definitely a hack.) Here, `int` is just a convenient alias for a full-fledged template class that deserializes integers—a little overkill for that case, but that's how deserialization is optionally made client-specific.\r\n\r\nThe neat thing about Confit currently is that the view system lets you be flexible about when you do validation for what. You can of course validate an entire configuration at once, but if you have a very large application, you can *modularize* the validation. For example, if you have two variables, foo and bar, you can either:\r\n\r\n    validated = config.get({'foo': int, 'bar': str})\r\n    print(validated['foo'], validated['bar'])\r\n\r\nor:\r\n\r\n    print(validated['foo'].get(int))\r\n    print(validated['bar'].get(str))\r\n\r\n---\r\n\r\nOn serialization: Would a goal be to re-emit a valid configuration file that could feasibly be parsed again? This could be useful, for example, if an application wants to be able to programmatically update the configuration file."}}