{"id":36629,"date":"2022-07-29T15:51:58","date_gmt":"2022-07-29T19:51:58","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=36629"},"modified":"2022-08-02T13:57:11","modified_gmt":"2022-08-02T17:57:11","slug":"deep-codable","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/07\/29\/deep-codable\/","title":{"rendered":"Deep Codable"},"content":{"rendered":"<p><a href=\"https:\/\/forums.swift.org\/t\/deepcodable-encode-and-decode-deeply-nested-data-into-flat-swift-objects\/59136\">Mike Lewis<\/a> (via <a href=\"https:\/\/iosdevweekly.com\/issues\/568?#start\">Dave Verwer<\/a>):<\/p>\n<blockquote cite=\"https:\/\/forums.swift.org\/t\/deepcodable-encode-and-decode-deeply-nested-data-into-flat-swift-objects\/59136\">\n<p>I recently built <a href=\"https:\/\/github.com\/MPLew-is\/deep-codable\">DeepCodable<\/a>, a package to encode and decode arbitrarily-nested data into flat Swift structs, by defining the coding paths with a result builder. I personally have been wanting something like this for a long time when interacting with third-party APIs, so I decided to build it.<\/p>\n<\/blockquote>\n\n<p id=\"deep-codable-update-2022-08-02\">Update (2022-08-02): <a href=\"https:\/\/github.com\/NSExceptional\/Jsum\">Jsum<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/NSExceptional\/Jsum\"><p>Jsum is a JSON object-mapping framework that aims to replace Codable for JSON object mapping. It takes a lot of inspiration from Mantle, if you&rsquo;ve ever used it back in Objective-C land.<\/p><p>[&#8230;]<\/p><p>Codable is often thought of as not being flexible enough. Many common problems with it are outlined in the replies to <a href=\"https:\/\/forums.swift.org\/t\/serialization-in-swift\/46641\">this Swift Forums post<\/a>. In my opinion, Codable requires you to give up its most valuable feature&mdash;synthesized initializers&mdash;too often, and this is why it feels so cumbersome to use.<\/p><p>Codable and <code>JSONDecoder<\/code> don&rsquo;t offer a lot of up-front decoding customization, and miss a lot of common use cases. All of these missed use cases mean you have to implement <code>init(decoder:)<\/code> and manually decode every single property for that type, even if you only needed to adjust a single property&rsquo;s behavior.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Mike Lewis (via Dave Verwer): I recently built DeepCodable, a package to encode and decode arbitrarily-nested data into flat Swift structs, by defining the coding paths with a result builder. I personally have been wanting something like this for a long time when interacting with third-party APIs, so I decided to build it. Update (2022-08-02): [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2022-07-29T19:52:01Z","apple_news_api_id":"f9f042c5-6b7a-42ae-bda3-bb3785a3967a","apple_news_api_modified_at":"2022-08-02T17:57:15Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/A-fBCxWt6Qq69o7s3haOWeg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[507,74,71,1774,901],"class_list":["post-36629","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-json","tag-opensource","tag-programming","tag-swift-codable","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=36629"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36629\/revisions"}],"predecessor-version":[{"id":36639,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36629\/revisions\/36639"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=36629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=36629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=36629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}