{"action":"created","issue":{"url":"https://api.github.com/repos/gilt/apidoc/issues/312","labels_url":"https://api.github.com/repos/gilt/apidoc/issues/312/labels{/name}","comments_url":"https://api.github.com/repos/gilt/apidoc/issues/312/comments","events_url":"https://api.github.com/repos/gilt/apidoc/issues/312/events","html_url":"https://github.com/gilt/apidoc/issues/312","id":66689234,"number":312,"title":"Difficult to debug Union types","user":{"login":"rlmartin","id":1110255,"avatar_url":"https://avatars.githubusercontent.com/u/1110255?v=3","gravatar_id":"","url":"https://api.github.com/users/rlmartin","html_url":"https://github.com/rlmartin","followers_url":"https://api.github.com/users/rlmartin/followers","following_url":"https://api.github.com/users/rlmartin/following{/other_user}","gists_url":"https://api.github.com/users/rlmartin/gists{/gist_id}","starred_url":"https://api.github.com/users/rlmartin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlmartin/subscriptions","organizations_url":"https://api.github.com/users/rlmartin/orgs","repos_url":"https://api.github.com/users/rlmartin/repos","events_url":"https://api.github.com/users/rlmartin/events{/privacy}","received_events_url":"https://api.github.com/users/rlmartin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-06T19:46:05Z","updated_at":"2015-04-06T19:54:58Z","closed_at":null,"body":"Because the jsonReadsXXX implicit method waterfalls through the union type options using orElse, it essentially \"matches\" on the first successful parsing. Conversely, when it fails, it will show the failure of the last class in the waterfall - not the one called out by the classname in the json. This makes debugging difficult, since you will have no idea which json properties are missing (unless the class you care about is the last one in the waterfall).\r\n\r\nMReed is thinking the fold method here (https://www.playframework.com/documentation/2.3.x/api/scala/index.html#play.api.libs.json.JsResult) could be a solution here."},"comment":{"url":"https://api.github.com/repos/gilt/apidoc/issues/comments/90222806","html_url":"https://github.com/gilt/apidoc/issues/312#issuecomment-90222806","issue_url":"https://api.github.com/repos/gilt/apidoc/issues/312","id":90222806,"user":{"login":"haywood","id":1062477,"avatar_url":"https://avatars.githubusercontent.com/u/1062477?v=3","gravatar_id":"","url":"https://api.github.com/users/haywood","html_url":"https://github.com/haywood","followers_url":"https://api.github.com/users/haywood/followers","following_url":"https://api.github.com/users/haywood/following{/other_user}","gists_url":"https://api.github.com/users/haywood/gists{/gist_id}","starred_url":"https://api.github.com/users/haywood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haywood/subscriptions","organizations_url":"https://api.github.com/users/haywood/orgs","repos_url":"https://api.github.com/users/haywood/repos","events_url":"https://api.github.com/users/haywood/events{/privacy}","received_events_url":"https://api.github.com/users/haywood/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T19:54:58Z","updated_at":"2015-04-06T19:54:58Z","body":"Actually, an even better approach is probably to look for each key in turn, and commit to parsing the appropriate class if one of the known keys is present. If none of the known keys is there, then a validation error indicating this should be returned.\r\n\r\nWhat I was thinking with the fold solution was to collect the errors as each alternative was tried, but I think the above is much more straightforward."}}