Skip to content

Commit

Permalink
Update JsonMapper.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark authored Nov 13, 2020
1 parent b52a38e commit 06b304a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Sources/JsonMapper/JsonMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public enum JSONElement: Codable, Equatable, Hashable {
}

public init(rawJSON: Data, jsonDecoder: JSONDecoder = JSONDecoder()) throws {
let jsonData = try JSONSerialization.data(withJSONObject: rawJSON, options: [])
self = try jsonDecoder.decode(JSONElement.self, from: jsonData)
self = try jsonDecoder.decode(JSONElement.self, from: rawJSON)
}

public init(unknownValue: Any, jsonDecoder: JSONDecoder = JSONDecoder()) throws {
Expand Down Expand Up @@ -224,7 +223,7 @@ public enum JSONElement: Codable, Equatable, Hashable {

public subscript(keyPath path: String) -> JSONElement {
var current = self
for key in path.split(separator: ",") {
for key in path.split(separator: ".") {
switch self {
case .null:
return .null
Expand Down Expand Up @@ -457,4 +456,4 @@ extension Encodable {
public func string(using encoder: JSONEncoder = JSONEncoder()) throws -> String {
return try String(data: encoder.encode(self), encoding: .utf8)!
}
}
}

0 comments on commit 06b304a

Please sign in to comment.