{"action":"created","issue":{"url":"https://api.github.com/repos/smithlamar/route_tracker_api/issues/4","repository_url":"https://api.github.com/repos/smithlamar/route_tracker_api","labels_url":"https://api.github.com/repos/smithlamar/route_tracker_api/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/smithlamar/route_tracker_api/issues/4/comments","events_url":"https://api.github.com/repos/smithlamar/route_tracker_api/issues/4/events","html_url":"https://github.com/smithlamar/route_tracker_api/issues/4","id":215275220,"number":4,"title":"Refactor BustimeAPIRequest class to take advantage of Spring Boot and Jackson automatic deserialization features.","user":{"login":"smithlamar","id":17191546,"avatar_url":"https://avatars1.githubusercontent.com/u/17191546?v=3","gravatar_id":"","url":"https://api.github.com/users/smithlamar","html_url":"https://github.com/smithlamar","followers_url":"https://api.github.com/users/smithlamar/followers","following_url":"https://api.github.com/users/smithlamar/following{/other_user}","gists_url":"https://api.github.com/users/smithlamar/gists{/gist_id}","starred_url":"https://api.github.com/users/smithlamar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smithlamar/subscriptions","organizations_url":"https://api.github.com/users/smithlamar/orgs","repos_url":"https://api.github.com/users/smithlamar/repos","events_url":"https://api.github.com/users/smithlamar/events{/privacy}","received_events_url":"https://api.github.com/users/smithlamar/received_events","type":"User","site_admin":false},"labels":[{"id":552745889,"url":"https://api.github.com/repos/smithlamar/route_tracker_api/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-03-19T16:23:57Z","updated_at":"2017-03-25T08:27:10Z","closed_at":null,"body":"As it stands, all parsing of CTA requests and desirialization of the objects contained within each payload is handled manually (albeit using Jackson core elements). The general goal is to see how far we can get with annotations and either RestTemplate and/or ObjectMapper to handle the deserialization and possibly the calls to the CTA for us.\r\n\r\nThis would make BustimeAPIRequest more lightweight and easier to reason with overall. The examples I've seen so far of this sort of implementation involve very pretty pojos that get deserialized from the Json response. It seems to get trickier when collections that use generics are the destination for the deserialized response. It gets trickier more so because some of these generic collections are contained within properties of the BusLine objects. A BusLine's _directions_ is a list of _Direction_ objects. Each _Direction_ within _BusLine.directions_ contains a List of _Stop_ objects.\r\n\r\nCTA response example:\r\n```\r\n`\t\"bustime-response\": {\r\n\t\t\"routes\": [\r\n\t\t\t{\r\n\t\t\t\t\"rt\": \"1\",\r\n\t\t\t\t\"rtnm\": \"Bronzeville/Union Station\",\r\n\t\t\t\t\"rtclr\": \"#336633\",\r\n\t\t\t\t\"rtdd\": \"1\"\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\t\"rt\": \"2\",\r\n\t\t\t\t\"rtnm\": \"Hyde Park Express\",\r\n\t\t\t\t\"rtclr\": \"#993366\",\r\n\t\t\t\t\"rtdd\": \"2\"\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\t\"rt\": \"3\",\r\n\t\t\t\t\"rtnm\": \"King Drive\",\r\n\t\t\t\t\"rtclr\": \"#009900\",\r\n\t\t\t\t\"rtdd\": \"3\"\r\n\t\t\t},\r\n                        ... # more and more routes\r\n                    ]\r\n      }\r\n`\r\n```\r\n\r\nThis response ties to what is essentially a List<BusLine> object, but only part of the data required for a complete BusLine object as we've defined it is here. The data for the _directions_ property is retrieved from a different endpoint of the CTA API but we are treating it as just another component of a BusLine. We can probably use _@JsonIgnoreProperties(ignoreUnknown=true)_ to keep the parser from failing where it doesn't find matching properties. We can also set unwrapwroot for deserialization in _application.properties_ to deal with the wrapping \"bustime-response\" root that is a part of every response. \r\n\r\nRestTemplate can theoretically take our class and map the Json response to it in addition to making the request with a supplied URL. The issue is when the class in this case is a generic collection. RestTemplate needs the type information but type erasure gets in the way when generics are involved. This seemed to be an issue that required some inelegant solutions in previous versions of Spring. I need to experiment a bit to figure out how to get this to work well without dirtying up the BusLine class with a ton of Json focused annotations or logic that ultimately is harder to reason with than manually deserializing the response to begin with.\r\n\r\nAnother concern is that we still need to be able to differentiate payloads from the CTA that contain error messages from those that have payloads that we actually want to build objects from and I haven't seen any indication that we can dig through the response returned from RestTemplate any easier than the way it currently is just by manually sending the request and checking the keys that are present."},"comment":{"url":"https://api.github.com/repos/smithlamar/route_tracker_api/issues/comments/289197790","html_url":"https://github.com/smithlamar/route_tracker_api/issues/4#issuecomment-289197790","issue_url":"https://api.github.com/repos/smithlamar/route_tracker_api/issues/4","id":289197790,"user":{"login":"smithlamar","id":17191546,"avatar_url":"https://avatars1.githubusercontent.com/u/17191546?v=3","gravatar_id":"","url":"https://api.github.com/users/smithlamar","html_url":"https://github.com/smithlamar","followers_url":"https://api.github.com/users/smithlamar/followers","following_url":"https://api.github.com/users/smithlamar/following{/other_user}","gists_url":"https://api.github.com/users/smithlamar/gists{/gist_id}","starred_url":"https://api.github.com/users/smithlamar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smithlamar/subscriptions","organizations_url":"https://api.github.com/users/smithlamar/orgs","repos_url":"https://api.github.com/users/smithlamar/repos","events_url":"https://api.github.com/users/smithlamar/events{/privacy}","received_events_url":"https://api.github.com/users/smithlamar/received_events","type":"User","site_admin":false},"created_at":"2017-03-25T08:27:10Z","updated_at":"2017-03-25T08:27:10Z","body":"I found a reasonable method to avoid having to use wrapper classes. Calls to the CTA API are made with RestTemplate and parsed into a ResponseEntity. This allows for easy response code checking down the line (even though the CTA API always returns 200 and wraps error messages in the body). \r\n\r\nFor handling json unmarshalling, JsonPath was significantly easier to reason with than the Jackson/RestTemplate combo  given that the objects we really wanted were hidden by a couple of top level objects with unwieldy types. JsonPath lets us use Json dot notation to dig through the response to our hearts content.\r\n\r\nThe element that I dislike is that checking for the presence of an error node with JsonPath (at least in my current implementation of it) results in a PathNotFoundException when not found. This isn't so bad but it might be worth finding a way around because catching that exception is the only indicator that no error message is present in the response. The exception acts as a null value for a hasError variable. I need to investigate the configuration options and see if the exception can be suppressed and have the return value coerced to null when no error message is present. "}}
{"actor":{"display_login":"smithlamar"}}