firebase / firebase/firebase-ios-sdk

BUG DECODING KEYS FROM FIRESTORE.

Open
#12,729 16 comments 2 reactions 2 assignees Claimed by @tom-andersen View on GitHub
api: firestore
Dominant language
C++
Stars
6.7k
Forks
1.8k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description

The firestore decoder keep in mind _JSONStringDictionaryDecodableMarker.Type. So for maps, if we have something like this:

``
{
"name": {"KEY": VALUE }
}
``

and we decode it with a codable structure with a property of type `[String: String]` it works.

The Behavior using `[EnumStringRawValue: String]` does fail into:
```
typeMismatch : 2 elements
- .0 : Swift.Array
▿ .1 : Context
▿ codingPath : 1 element
- 0 : CodingKeys(stringValue: "KEY", intValue: nil)
- debugDescription : "Expected to decode Array but found a dictionary instead."
- underlyingError : nil
```
Because in this case key is always represented as a String
```
extension Dictionary : _JSONStringDictionaryDecodableMarker where Key == String, Value: Decodable {
static var elementType: Decodable.Type { return Value.self }
}
```

The expected behavior is to decode a map with an enum string raw representable if it can fit on the string raw representable cases.

### Reproducing the issue

Add a document with a map in Firestore.

Try to decode it with document.data() passing as an argument your struct or class metatype. Inside of the struct or class metatype define a map with StringRawValueEnum as key.

### Firebase SDK Version

10.23.0

### Xcode Version

15.2

### Installation Method

Swift Package Manager

### Firebase Product(s)

Firestore

### Targeted Platforms

iOS

### Relevant Log Output

_No response_

### If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet

```json

Replace this line with the contents of your Package.resolved.

```

### If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet

```yml

Replace this line with the contents of your Podfile.lock!

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.