@@ -1214,9 +1214,9 @@ private extension __JSONEncoder {
1214
1214
return self . wrap ( url. absoluteString)
1215
1215
} else if let decimal = value as? Decimal {
1216
1216
return . number( decimal. description)
1217
- } else if let encodable = value as? _JSONStringDictionaryEncodableMarker {
1217
+ } else if !options . keyEncodingStrategy . isDefault , let encodable = value as? _JSONStringDictionaryEncodableMarker {
1218
1218
return try self . wrap ( encodable as! [ String : Encodable ] , for: additionalKey)
1219
- } else if let array = value as? _JSONDirectArrayEncodable {
1219
+ } else if let array = _asDirectArrayEncodable ( value, for : additionalKey ) {
1220
1220
if options. outputFormatting. contains ( . prettyPrinted) {
1221
1221
let ( bytes, lengths) = try array. individualElementRepresentation ( encoder: self , additionalKey)
1222
1222
return . directArray( bytes, lengths: lengths)
@@ -1246,6 +1246,42 @@ private extension __JSONEncoder {
1246
1246
return encoder. takeValue ( )
1247
1247
}
1248
1248
1249
+ func _asDirectArrayEncodable< T: Encodable > ( _ value: T , for additionalKey: ( some CodingKey ) ? = _CodingKey? . none) -> _JSONDirectArrayEncodable ? {
1250
+ return if let array = _specializingCast ( array, to: [ Int8 ] . self) {
1251
+ array
1252
+ } else if let array = _specializingCast ( array, to: [ Int16 ] . self) {
1253
+ array
1254
+ } else if let array = _specializingCast ( array, to: [ Int32 ] . self) {
1255
+ array
1256
+ } else if let array = _specializingCast ( array, to: [ Int64 ] . self) {
1257
+ array
1258
+ } else if let array = _specializingCast ( array, to: [ Int128 ] . self) {
1259
+ array
1260
+ } else if let array = _specializingCast ( array, to: [ Int ] . self) {
1261
+ array
1262
+ } else if let array = _specializingCast ( array, to: [ UInt8 ] . self) {
1263
+ array
1264
+ } else if let array = _specializingCast ( array, to: [ UInt16 ] . self) {
1265
+ array
1266
+ } else if let array = _specializingCast ( array, to: [ UInt32 ] . self) {
1267
+ array
1268
+ } else if let array = _specializingCast ( array, to: [ UInt64 ] . self) {
1269
+ array
1270
+ } else if let array = _specializingCast ( array, to: [ UInt128 ] . self) {
1271
+ array
1272
+ } else if let array = _specializingCast ( array, to: [ UInt ] . self) {
1273
+ array
1274
+ } else if let array = _specializingCast ( array, to: [ String ] . self) {
1275
+ array
1276
+ } else if let array = _specializingCast ( array, to: [ Float ] . self) {
1277
+ array
1278
+ } else if let array = _specializingCast ( array, to: [ Double ] . self) {
1279
+ array
1280
+ } else {
1281
+ nil
1282
+ }
1283
+ }
1284
+
1249
1285
@inline ( __always)
1250
1286
func getEncoder( for additionalKey: CodingKey ? ) -> __JSONEncoder {
1251
1287
if let additionalKey {
@@ -1466,3 +1502,14 @@ extension Array : _JSONDirectArrayEncodable where Element: _JSONSimpleValueArray
1466
1502
return ( writer. bytes, lengths: byteLengths)
1467
1503
}
1468
1504
}
1505
+
1506
+ fileprivate extension JSONEncoder . KeyEncodingStrategy {
1507
+ var isDefault : Bool {
1508
+ switch self {
1509
+ case . useDefaultKeys:
1510
+ return true
1511
+ case . custom, . convertToSnakeCase:
1512
+ return false
1513
+ }
1514
+ }
1515
+ }
0 commit comments