skiptools / skiptools/skip-foundation

Skip cannot Encode optional dictionary

Open
#62 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.