4.0.0-beta.1 版本数组模型转换 toJSON 的时候会有 Optional 关键字?
- Dominant language
- Swift
- Stars
- 4.3k
- Forks
- 677
- PR merge metrics
- No merged PRs in 30d
Description
模型:
```swift
struct WNResume: HandyJSON {
// 这里有其他属性,先不管
/// 技能培训
struct SkillTraining: HandyJSON {
var star_time: UInt64? // "时间戳",
var end_time: UInt64? // "时间戳",
var skill: String? // "技能",
var skill_content: String? // "技能描述"
}
}
```
我往SkillTraining 数组添加数据之后,并将其 toJSON 后作为参数传递给后台:
```swift
var skillTrainings = [WNResume.SkillTraining]()
for i in 0 ..< 5 {
var skill = WNResume.SkillTraining()
skill.end_time = 12
skill.star_time = 34
skill.skill = "12 \(i)"
skill.skill_content = "666 \(i)"
skillTrainings.append(skill)
}
print(skillTrainings.toJSON())
```
打印结果如下:

我想要去掉 Optional 关键字,我尝试过将所有属性置为不可选,即类似:
```swift
var end_time: UInt64 = 0 // "时间戳",
var skill: String = "" // "技能",
```
依旧不起作用。
我看到在 https://github.com/alibaba/HandyJSON/issues/160 说在 1.8.0 版本已经修复了这个,但我在4.0.0-beta.1 版本下还是有这个问题,望解答。
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue with the WNResume.SkillTraining model and its array's toJSON call, comparing optional and non-optional properties. Trace the serialization path used by toJSON; the work is done when the generated JSON no longer contains Optional wrappers for these values and the behavior is covered by a regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100