Support for a KeyCodingStrategy option in JSONEncoder and JSONDecoder

Yes, in general, I think Codable is a poor solution for json decoding just

like I never used NSCoding to convert JSON to and from objects. It feels
clumsy.

I found it a much better solution to add a category to NSObject that had

-(NSData*)toJSONRepresentationWithMappings:(NSDictionary*)d
+()fromJSONRepresentation:(NSData*) mappings:(NSDictionary*)d

where mappings might be { @"firstName": @"first_name", etc.... }

and was simple to write a general solution using introspection and KVC.

Codable is a limited one trick pony that would be trivial to write as a
trait or extension if Swift provided the more profound thing -
introspection and reflection. A whole world of opportunities would open up
with that and we could stop wasting time on Codable and KeyPath - neither
of which is that useful when working with string data from the wild.

i found Codable very useful. when you need to translate the keys it's a bit
awkward and looks "unfinished" but if you don't need the translation you
literally write no code at all which is good.

having Codable does not contradict having introspection /
reflection. general (or shall we say custom) approaches that use
introspection / reflection tend to work much slower (from Objective-C
experience). i have no data if Codable is performant in these regards but
at least it has a potential to be more optimal than a general solution
based on introspection / reflection.

Mike

···

on 19 Oct 2017 11:21:39 -0700 Eagle Offshore <eagleoffshore@mac.com> wrote:

having Codable does not contradict having introspection / reflection.

But we don't have general introspection/reflection/dynamic invocation. Which would have been a more worthwhile thing to spend time on as it enables many more features.

general (or shall we say custom) approaches that use introspection / reflection tend to work much slower (from Objective-C experience). i have no data if Codable is performant in these regards but at least it has a potential to be more optimal than a general solution based on introspection / reflection.

Performance is at the very bottom of my list of things I care about - especially with regard to JSON processing or other format translations where the program is IO bound.

My Objective C KVC based mapper to SQLite was incredibly performant with mapkit when I was mapping thousands of pins stored in a very large local database. Performance, as an argument against flexibility, is completely unpersuasive.

Stuff is much more than fast enough in the application domain.

···

On Oct 23, 2017, at 3:19 AM, Mike Kluev via swift-evolution <swift-evolution@swift.org> wrote: