{"action":"created","issue":{"url":"https://api.github.com/repos/glennsl/bs-json/issues/23","repository_url":"https://api.github.com/repos/glennsl/bs-json","labels_url":"https://api.github.com/repos/glennsl/bs-json/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/glennsl/bs-json/issues/23/comments","events_url":"https://api.github.com/repos/glennsl/bs-json/issues/23/events","html_url":"https://github.com/glennsl/bs-json/issues/23","id":297043712,"number":23,"title":"optionalField Decoder ","user":{"login":"ncthbrt","id":8688217,"avatar_url":"https://avatars0.githubusercontent.com/u/8688217?v=4","gravatar_id":"","url":"https://api.github.com/users/ncthbrt","html_url":"https://github.com/ncthbrt","followers_url":"https://api.github.com/users/ncthbrt/followers","following_url":"https://api.github.com/users/ncthbrt/following{/other_user}","gists_url":"https://api.github.com/users/ncthbrt/gists{/gist_id}","starred_url":"https://api.github.com/users/ncthbrt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncthbrt/subscriptions","organizations_url":"https://api.github.com/users/ncthbrt/orgs","repos_url":"https://api.github.com/users/ncthbrt/repos","events_url":"https://api.github.com/users/ncthbrt/events{/privacy}","received_events_url":"https://api.github.com/users/ncthbrt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2018-02-14T10:27:11Z","updated_at":"2018-04-19T14:16:39Z","closed_at":null,"author_association":"NONE","body":"When parsing user input it's important to be able to give good error messages. For example in a http PATCH request, the `date_of_birth` field might only accept a UTC conformant string when the field is present. If a user passes in a number, we need to return with a `400 BAD REQUEST`.\r\n\r\nWhen using the `optional` decoder in combination with the field decoder, if the field exists but the inner decoder fails, the final result will be `None`. \r\n\r\nIn the previous example `{ dateOfBirth: optional(field(\"date_of_birth\", utcString)) }` when fed with the payload `{ \"date_of_birth\": 1234 }`  would simply be `{ dateOfBirth: None }`. The actual semantics that needed to be captured in this example was:\r\n-  `{ }` becomes `{ dateOfBirth: None }`\r\n-  `{ \"date_of_birth\": \"Wed, 14 Feb 2018 10:22:19 GMT\" }` becomes `{ dateOfBirth: Some(\"Wed, 14 Feb 2018 10:22:19 GMT\")`\r\n- `{ \"date_of_birth\": 123457 }` becomes `Json.Decoder.DecoderError(\"Expected a UTC string, got a number\")`\r\n\r\nAn `optionalField` decoder (or a decoder with a similar name) would solve this problem by returning `None` if the field is `undefined`, else would bubble up the error from inner decoder."},"comment":{"url":"https://api.github.com/repos/glennsl/bs-json/issues/comments/382753298","html_url":"https://github.com/glennsl/bs-json/issues/23#issuecomment-382753298","issue_url":"https://api.github.com/repos/glennsl/bs-json/issues/23","id":382753298,"user":{"login":"ncthbrt","id":8688217,"avatar_url":"https://avatars0.githubusercontent.com/u/8688217?v=4","gravatar_id":"","url":"https://api.github.com/users/ncthbrt","html_url":"https://github.com/ncthbrt","followers_url":"https://api.github.com/users/ncthbrt/followers","following_url":"https://api.github.com/users/ncthbrt/following{/other_user}","gists_url":"https://api.github.com/users/ncthbrt/gists{/gist_id}","starred_url":"https://api.github.com/users/ncthbrt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncthbrt/subscriptions","organizations_url":"https://api.github.com/users/ncthbrt/orgs","repos_url":"https://api.github.com/users/ncthbrt/repos","events_url":"https://api.github.com/users/ncthbrt/events{/privacy}","received_events_url":"https://api.github.com/users/ncthbrt/received_events","type":"User","site_admin":false},"created_at":"2018-04-19T14:16:39Z","updated_at":"2018-04-19T14:16:39Z","author_association":"NONE","body":"@glennsl This looks like a promising approach. Looking at our decoder usage, it isn't very far removed from how your provisional design looks, but with a bit of extra verbosity introduced from the repeated field decoders. "}}
{"actor":{"display_login":"ncthbrt"}}