File tree 1 file changed +5
-11
lines changed
1 file changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -188,17 +188,11 @@ extension ASCIICharacter: Equatable {
188
188
189
189
extension ASCIICharacter : Codable {
190
190
191
- enum CodingKeys : String , CodingKey {
192
-
193
- case asciiValue
194
-
195
- }
196
-
197
191
public init ( from decoder: Decoder ) throws {
198
192
199
- let container = try decoder. container ( keyedBy : CodingKeys . self )
200
- let asciiValue = try container. decode ( UInt8 . self, forKey : . asciiValue )
201
- guard let newInstance = Self ( asciiValue ) else {
193
+ let container = try decoder. singleValueContainer ( )
194
+ let string = try container. decode ( String . self)
195
+ guard let newInstance = Self ( exactly : string ) else {
202
196
throw DecodingError . dataCorrupted (
203
197
. init( codingPath: container. codingPath,
204
198
debugDescription: " Value was not valid ASCII character number. " )
@@ -210,9 +204,9 @@ extension ASCIICharacter: Codable {
210
204
211
205
public func encode( to encoder: Encoder ) throws {
212
206
213
- var container = encoder. container ( keyedBy : CodingKeys . self )
207
+ var container = encoder. singleValueContainer ( )
214
208
215
- try container. encode ( asciiValue , forKey : . asciiValue )
209
+ try container. encode ( String ( characterValue ) )
216
210
217
211
}
218
212
You can’t perform that action at this time.
0 commit comments