Skip to content

Commit a0f84ef

Browse files
committed
fix styling and remove extra diff
1 parent 45a07ab commit a0f84ef

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Sources/FoundationEssentials/JSON/JSONDecoder.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,8 @@ extension JSONDecoderImpl: Decoder {
610610
if type == Decimal.self {
611611
return try self.unwrapDecimal(from: mapValue, for: codingPathNode, additionalKey) as! T
612612
}
613-
switch options.keyDecodingStrategy {
614-
case .useDefaultKeys:
615-
break
616-
case .convertFromSnakeCase, .custom:
617-
if T.self is _JSONStringDictionaryDecodableMarker.Type {
618-
return try self.unwrapDictionary(from: mapValue, as: type, for: codingPathNode, additionalKey)
619-
}
613+
if !options.keyDecodingStrategy.isDefault, T.self is _JSONStringDictionaryDecodableMarker.Type {
614+
return try self.unwrapDictionary(from: mapValue, as: type, for: codingPathNode, additionalKey)
620615
}
621616

622617
return try self.with(value: mapValue, path: codingPathNode.appending(additionalKey)) {
@@ -1862,5 +1857,14 @@ extension EncodingError {
18621857
}
18631858
}
18641859

1860+
extension JSONDecoder.KeyDecodingStrategy {
1861+
fileprivate var isDefault: Bool {
1862+
switch self {
1863+
case .useDefaultKeys: true
1864+
default: false
1865+
}
1866+
}
1867+
}
1868+
18651869
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
18661870
extension JSONDecoder : @unchecked Sendable {}

Sources/FoundationEssentials/JSON/JSONEncoder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,12 +1216,12 @@ private extension __JSONEncoder {
12161216
return .number(decimal.description)
12171217
} else if !options.keyEncodingStrategy.isDefault, let encodable = value as? _JSONStringDictionaryEncodableMarker {
12181218
return try self.wrap(encodable as! [String:Encodable], for: additionalKey)
1219-
} else if let directArrayEncodable = _asDirectArrayEncoding(value, for: additionalKey) {
1219+
} else if let array = _asDirectArrayEncodable(value, for: additionalKey) {
12201220
if options.outputFormatting.contains(.prettyPrinted) {
1221-
let (bytes, lengths) = try directArrayEncodable.individualElementRepresentation(encoder: self, additionalKey)
1221+
let (bytes, lengths) = try array.individualElementRepresentation(encoder: self, additionalKey)
12221222
return .directArray(bytes, lengths: lengths)
12231223
} else {
1224-
return .nonPrettyDirectArray(try directArrayEncodable.nonPrettyJSONRepresentation(encoder: self, additionalKey))
1224+
return .nonPrettyDirectArray(try array.nonPrettyJSONRepresentation(encoder: self, additionalKey))
12251225
}
12261226
}
12271227

@@ -1246,7 +1246,7 @@ private extension __JSONEncoder {
12461246
return encoder.takeValue()
12471247
}
12481248

1249-
func _asDirectArrayEncoding<T: Encodable>(_ value: T, for additionalKey: (some CodingKey)? = _CodingKey?.none) -> _JSONDirectArrayEncodable? {
1249+
func _asDirectArrayEncodable<T: Encodable>(_ value: T, for additionalKey: (some CodingKey)? = _CodingKey?.none) -> _JSONDirectArrayEncodable? {
12501250
return if let array = _specializingCast(array, to: [Int8].self) {
12511251
array
12521252
} else if let array = _specializingCast(array, to: [Int16].self) {

0 commit comments

Comments
 (0)