alibaba / alibaba/HandyJSON

当JSON字段出现子字段重名时toJSON异常---4.0.0-beta.1

Open
#228 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

例如,当某个JSON字段类似这种结构["father": ["name": "Li"], "mother": ["name": "Wang"]]

struct Child: HandyJSON {
var father: String = ""
var mother: String = ""
mutating func mapping(mapper: HelpingMapper) {
mapper <<< father <-- "father.name"
mapper <<< mother <-- "mother.name"
}
}
let childJSON = ["father": ["name": "Li"], "mother": ["name": "Wang"]]
let child = Child.deserialize(from: childJSON)
print(child ?? "失败")
print(child?.toJSON() ?? "失败")
deserialize可以成功,但是toJSON结果异常:
Child(father: "Li", mother: "Wang")
["name": "Wang"]

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the issue with the supplied Child struct, nested father and mother name fields, and HelpingMapper mappings. Compare deserialize and toJSON results; done means both mapped child fields serialize without one nested name overwriting the other.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.