Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Decoding null inside an array does not work #22

Open
2 of 12 tasks
antkont opened this issue Jun 26, 2023 · 0 comments
Open
2 of 12 tasks

[BUG]: Decoding null inside an array does not work #22

antkont opened this issue Jun 26, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@antkont
Copy link

antkont commented Jun 26, 2023

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> 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.

  • 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
  • Swift Package Manager
  • Other (Please specify in "Additional Context" section)

Additional Context

No response

@antkont antkont added the bug Something isn't working label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants