Remove previous hack for SR-5206

As a temporary workaround for SR-5206, certain Foundation types which had custom behavior in JSONEncoder and JSONDecoder were granted special knowledge of those types internally in order to preserve strategies on encode/decode.

This replaces that special knowledge with a more general-purpose fix that works for all types and all encoders/decoders.
This commit is contained in:
Itai Ferber
2017-08-02 14:07:11 -07:00
parent d495e1c075
commit fbdcbee7a2
6 changed files with 50 additions and 147 deletions

View File

@@ -1214,17 +1214,6 @@ extension URL : Codable {
}
public init(from decoder: Decoder) throws {
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
do {
// We are allowed to request this container as long as we don't decode anything through it when we need the keyed container below.
let singleValueContainer = try decoder.singleValueContainer()
if singleValueContainer is _JSONDecoder {
// _JSONDecoder has a hook for URLs; this won't recurse since we're not going to defer back to URL in _JSONDecoder.
self = try singleValueContainer.decode(URL.self)
return
}
} catch { /* Fall back to default implementation below. */ }
let container = try decoder.container(keyedBy: CodingKeys.self)
let relative = try container.decode(String.self, forKey: .relative)
let base = try container.decodeIfPresent(URL.self, forKey: .base)
@@ -1238,15 +1227,6 @@ extension URL : Codable {
}
public func encode(to encoder: Encoder) throws {
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
// We are allowed to request this container as long as we don't encode anything through it when we need the keyed container below.
var singleValueContainer = encoder.singleValueContainer()
if singleValueContainer is _JSONEncoder {
// _JSONEncoder has a hook for URLs; this won't recurse since we're not going to defer back to URL in _JSONEncoder.
try singleValueContainer.encode(self)
return
}
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.relativeString, forKey: .relative)
if let base = self.baseURL {