alibaba / alibaba/HandyJSON

指定路径解析,如果路径下为数组模型出现无法解析的情况。

Open
#334 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
4.3k
Forks
677
PR merge metrics
No merged PRs in 30d

Description

需求样例:
![Screenshot 2019-05-24 at 11 29 14 AM](https://user-images.githubusercontent.com/22167530/58300960-3e88a180-7e17-11e9-91a8-27b44c977ef3.png)

datas.items内为数组时无法通过指定路径解析出。

在检查HandyJSON源码时发现是因为在
`deserializeFrom(dict:, designatedPath: )` 函数中并未对该情况进行处理,我对该函数进行了简单的处理,希望可以在后续版本中更新。
```
public static func deserializeFrom(dict: [String: Any]?, designatedPath: String? = nil) -> T? {
var targetDict = dict
var targetArray: [Any]?
if let path = designatedPath {
targetDict = getInnerObject(inside: targetDict, by: path) as? [String: Any]
if targetDict == nil {
targetArray = getInnerObject(inside: dict, by: path) as? [Any]
}
}
if let _dict = targetDict {
return T._transform(dict: _dict) as? T
}
if let _array = targetArray {
return T.transform(from: _array) as? T
}
return nil
}

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the public deserializeFrom(dict:, designatedPath:) function named in the issue and reproduce the provided case where datas.items contains an array. Check that a designated path resolving to an array can be deserialized successfully, while preserving the existing dictionary behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.