Skip to content

Add Encoding capabilities #7

@mdb1

Description

@mdb1
  • Add the extension to Encodable to transform an object to a dictionary.
public extension Encodable {
    /// Creates a json dictionary from an Encodable Object
    var toJsonDictionary: [String: Any] {
        let jsonEncoder: JSONEncoder = .default
        guard let data = try? jsonEncoder.encode(self) else { return [:] }
        let dictionary = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
        return dictionary ?? [:]
    }
}
  • Add the JSONEncoder to the HTTPClient and a convenient way to use Encodable models for post/put requests' bodies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions