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

@@ -478,17 +478,6 @@ extension Decimal : 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 Decimals; this won't recurse since we're not going to defer to Decimal in _JSONDecoder.
self = try singleValueContainer.decode(Decimal.self)
return
}
} catch { /* Fall back to default implementation below. */ }
let container = try decoder.container(keyedBy: CodingKeys.self)
let exponent = try container.decode(CInt.self, forKey: .exponent)
let length = try container.decode(CUnsignedInt.self, forKey: .length)
@@ -516,15 +505,6 @@ extension Decimal : 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 Decimals; this won't recurse since we're not going to defer to Decimal in _JSONEncoder.
try singleValueContainer.encode(self)
return
}
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(_exponent, forKey: .exponent)
try container.encode(_length, forKey: .length)