Skip to content

Commit

Permalink
build warning removed and snake case converted again when encoding mo…
Browse files Browse the repository at this point in the history
…del into JSON (JSON was converted to camel case when decoding), also, error thrown for serialisation of JSON
  • Loading branch information
Ayush Awasthi committed Jan 16, 2019
1 parent 06be45f commit 4f715b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion KiwiPods/Networking/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class NetworkManager: NSObject {
case .success(let value):
do {
decoder.keyDecodingStrategy = .convertFromSnakeCase
if let obj = try ModelClass.objectFrom(json: value, decoder: decoder) as? ModelClass {
if let obj = try ModelClass.objectFrom(json: value, decoder: decoder) {
let model = Response.ResponseValue(value: obj, statusCode: response.response?.statusCode)
completion(Response.success(model))
} else {
Expand Down
10 changes: 5 additions & 5 deletions KiwiPods/Networking/NetworkModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public extension ParameterConvertible {
}
public func toParams()throws -> [String: Any]? {
do {
let data = try JSONEncoder().encode(self)
if let dict = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any] {
return dict
}
return nil
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
let data = try encoder.encode(self)
let dict = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any]
return dict
} catch let error {
throw error
}
Expand Down

0 comments on commit 4f715b0

Please sign in to comment.