CBORCoding
CBORCoding copied to clipboard
[BUG]: Decoding null inside an array does not work
Expected Behavior
Decoding null values to nil should work inside an array.
Actual Behavior
Cannot decode and I get the following error:
valueNotFound(Swift.Optional<Swift.Array<Swift.Int>>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "m", intValue: nil), CodingKey(stringValue: "Index 1", intValue: 1), CodingKey(stringValue: "Index 1", intValue: 1)], debugDescription: "Expected Optional<Array<Int>> but found null instead.", underlyingError: nil))
Steps To Reproduce
Here is simple sample code:
struct CBORExample: Codable, Equatable {
var m: [[Int]?]? = nil
}
func test() {
let obj = CBORExample(m: [[1,2], nil, [3,4]])
do {
let encoder = CBOREncoder()
let encodedData = try encoder.encode(obj) // This works fine, checked the result with cbor.me
let decoder = CBORDecoder()
let decoded: CBORExample? = try decoder.decode(CBORExample.self, from: encodedData) // This fails
print("Decoded: \(String(describing: decoded))")
} catch {
print("\(error)")
}
}
Project Version
latest
The OS/Variant where this issue occurs.
- [X] iOS
- [ ] macOS
- [ ] tvOS
- [ ] watchOS
- [ ] Mac Catalyst
- [ ] Other (Please specify in "Additional Context" section)
The version of Xcode that was used when this issue appeared.
14.3.1
What was the environment in which the issue appeared?
- [ ] CBORCoding.xcodeproj
- [ ] Package.swift
- [ ] Carthage
- [ ] CocoaPods
- [X] Swift Package Manager
- [ ] Other (Please specify in "Additional Context" section)
Additional Context
No response
This seems to work for us. Nice work. Please could we get this merged?