You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Encode the `Date` as a string formatted by the given formatter.
53
-
case formatted(DateFormatter)
54
-
55
-
/// Encode the `Date` as a custom value encoded by the given closure.
56
-
///
57
-
/// If the closure fails to encode a value into the given encoder, the encoder will encode an empty automatic container in its place.
58
-
case custom((Date,Encoder)throws->Void)
59
-
}
60
-
61
-
/// The strategy to use for encoding `Data` values.
62
-
publicenumDataEncodingStrategy{
63
-
/// Defer to `Data` for choosing an encoding.
64
-
case deferredToData
65
-
66
-
/// Encoded the `Data` as a Base64-encoded string. This is the default strategy.
67
-
case base64
68
-
69
-
/// Encode the `Data` as a custom value encoded by the given closure.
70
-
///
71
-
/// If the closure fails to encode a value into the given encoder, the encoder will encode an empty automatic container in its place.
72
-
case custom((Data,Encoder)throws->Void)
73
-
}
74
-
75
-
/// The strategy to use for non-JSON-conforming floating-point values (IEEE 754 infinity and NaN).
76
-
publicenumNonConformingFloatEncodingStrategy{
77
-
/// Throw upon encountering non-conforming values. This is the default strategy.
78
-
case `throw`
79
-
80
-
/// Encode the values using the given representation strings.
81
-
case convertToString(positiveInfinity:String, negativeInfinity:String, nan:String)
82
-
}
83
-
84
-
/// The strategy to use for automatically changing the value of keys before encoding.
85
-
publicenumKeyEncodingStrategy{
86
-
/// Use the keys specified by each type. This is the default strategy.
87
-
case useDefaultKeys
88
-
89
-
/// Convert from "camelCaseKeys" to "snake_case_keys" before writing a key to JSON payload.
90
-
///
91
-
/// Capital characters are determined by testing membership in `CharacterSet.uppercaseLetters` and `CharacterSet.lowercaseLetters` (Unicode General Categories Lu and Lt).
92
-
/// The conversion to lower case uses `Locale.system`, also known as the ICU "root" locale. This means the result is consistent regardless of the current user's locale and language preferences.
93
-
///
94
-
/// Converting from camel case to snake case:
95
-
/// 1. Splits words at the boundary of lower-case to upper-case
96
-
/// 2. Inserts `_` between words
97
-
/// 3. Lowercases the entire string
98
-
/// 4. Preserves starting and ending `_`.
99
-
///
100
-
/// For example, `oneTwoThree` becomes `one_two_three`. `_oneTwoThree_` becomes `_one_two_three_`.
101
-
///
102
-
/// - Note: Using a key encoding strategy has a nominal performance cost, as each string key has to be converted.
103
-
case convertToSnakeCase
104
-
105
-
/// Provide a custom conversion to the key in the encoded JSON from the keys specified by the encoded types.
106
-
/// The full path to the current encoding position is provided for context (in case you need to locate this key within the payload). The returned key is used in place of the last component in the coding path before encoding.
107
-
/// If the result of the conversion is a duplicate key, then only one value will be present in the result.
108
-
case custom((_ codingPath:[CodingKey])->CodingKey)
// The general idea of this algorithm is to split words on transition from lower to upper case, then on transition of >1 upper case characters to lowercase
115
-
//
116
-
// myProperty -> my_property
117
-
// myURLProperty -> my_url_property
118
-
//
119
-
// We assume, per Swift naming conventions, that the first character of the key is lowercase.
// There are no more lower case letters. Just end here.
132
-
wordStart = searchRange.lowerBound
133
-
break
134
-
}
135
-
136
-
// Is the next lowercase letter more than 1 after the uppercase? If so, we encountered a group of uppercase letters that we should treat as its own word
/// - returns: A new `Data` value containing the encoded JSON data.
207
41
/// - throws: `EncodingError.invalidValue` if a non-conforming floating-point value is encountered during encoding, and the encoding strategy is `.throw`.
208
42
/// - throws: An error if any value throws an error during encoding.
0 commit comments