I know there's a lot of object mapping extensions for Alamofire around (like Alamofire-ObjectMapper) but since we now have the Codable type built into Swift 4's standard library I think it would make sense to consider adding them as first class citizens alongside the [String: Any] parameters and parameterEncoding strategy.
Specifically this would mean:
Encodable type and an encoder (like JSONEncoder) which will then be placed into the httpBody as Data (this is what the encoders .encode method returns).Decodable type using the received data, if possible.Note that this issue arised because we don't have support for Encodable objects as part of the request when only specifying parameters and parameterEncoding in this issue for the Moya project, which includes Alamofire as its dependency. Although I've laid out to them, how we can solve this without changing Alamofire, there's kind of an agreement that it would be great to hear if and how Alamofire plans to support the Encodable and/or Decodable protocol types.
I would love to see this in an addition to the existing, very flexible Alamofire-ObjectMapper.
Yeah great idea to modify it
Hi @Dschee,
I can say we are certainly planning on adding Decodable support to Alamofire 5, possibly even Alamofire 4. We haven't completed nailed that down yet. As for the Encodable support, that will take some more investigation. It gets quite complicated when considering different encoding types as well as query parameters vs. the http body.
Once we nail down some more specifics, we'll make sure to update this ticket.
Cheers. 馃嵒
@Dschee I've broken this up into Decodable and Encodable parts in #2180 and #2181 respectively. We can move discussion and other ideas to them. I've also created an Alamofire 5 project to track our design and implementation of new features for the next version.
@jshier Thanks for splitting this up. Looking forward to both of them being implemented!
Most helpful comment
Hi @Dschee,
I can say we are certainly planning on adding
Decodablesupport to Alamofire 5, possibly even Alamofire 4. We haven't completed nailed that down yet. As for theEncodablesupport, that will take some more investigation. It gets quite complicated when considering different encoding types as well as query parameters vs. the http body.Once we nail down some more specifics, we'll make sure to update this ticket.
Cheers. 馃嵒