xcode 10,当 json 里边有 null 时,赋值会崩溃
- Dominant language
- Swift
- Stars
- 4.3k
- Forks
- 677
- PR merge metrics
- No merged PRs in 30d
Description
HandyJSON 版本:4.2.0-beta1
我定义了一个继承自 NSObject, HandyJSON, NSCoding 的类型,当后台返回的 json 中某个字段的值是 null 时,会崩溃在类 ExtendCustomModelType 的 66 行。此时,convertedValue = nil。
定义的类型:
```
class GFUserInfo: NSObject, HandyJSON, NSCoding {
var sIM: String?
var state: String?
var cityCode: String?
var companyName: String?
var companyNameState: Int = 0
var headImg: String?
var nickName: String?
var userCertificationSwitch: Int = 0
var vcardState: Int = 0
var vlicenseState: Int = 0
var lastRemindTime: TimeInterval = 0
}
```
json:
```
"userInfo": {
"userID": "",
"sIM": "",
"nickName": "WHY",
"headImg": null,
"cardImgF": "",
"cardImgB": "",
"licenseO": "",
"licenseC": "",
"verifyCard": "1",
"verifyLicense": "1",
"verifyCredit": "1",
"verifyDeposit": "0"
}
```
同样的的代码,在 xcode 9,HandyJSON 版本 4.1.3 不会崩溃。
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at ExtendCustomModelType line 66 and reproduce the crash with the GFUserInfo model and the JSON containing a null headImg value. Compare the behavior with HandyJSON 4.1.3 and Xcode 9; done means the same null input no longer crashes under Xcode 10 and the affected mapping behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100