skiptools / skiptools/skip-foundation
Skip cannot Encode optional dictionary
Open
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 17
- Forks
- 16
- Avg merge
- 1h 50m
- Merged PRs (30d)
- 2
Description
Hello! When using JSONEncoder, dictionary types that are optional are not correctly encoded by Skip.
struct TestEntity2: Codable {
let optionalDict: [String: String]?
let nonOptionalDict: [String: String]
}
// This succeeds ✅
try! JSONEncoder().encode(TestEntity2(optionalDict: nil, nonOptionalDict: [:]))
// This fails ❌ data error skip.lib.ErrorException: java.lang.ClassCastException: skip.lib.Tuple2 cannot be cast to skip.lib.Encodable
try! JSONEncoder().encode(TestEntity2(optionalDict: ["1": "abc"], nonOptionalDict: ["1": "abc"]))
I'm currently working around by using a non optional dict and making it empty to represent nil.
Thank you!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the JSONEncoder path using the provided TestEntity2 reproducer, comparing optional and non-optional dictionary encoding. Done means encoding the populated optional dictionary succeeds without the Tuple2/ClassCastException while preserving the existing nil case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100