Created
February 1, 2018 07:48
-
-
Save Anatoli-Petrosyants/8a2b7052ef122cec28c523a2d534f53c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// MARK: Encode/decode helpers | |
class JSONNull: Codable { | |
public init() {} | |
public required init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
if !container.decodeNil() { | |
throw DecodingError.typeMismatch(JSONNull.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for JSONNull")) | |
} | |
} | |
public func encode(to encoder: Encoder) throws { | |
var container = encoder.singleValueContainer() | |
try container.encodeNil() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment