Nested json flated lost
- Dominant language
- Swift
- Stars
- 4.3k
- Forks
- 677
- PR merge metrics
- No merged PRs in 30d
Description
toJsonString() will lost nest json when use mapping
As the demo code says:
```swift
class Cat: HandyJSON {
var id: Int64
var myname: String!
var friendName: String?
func mapping(mapper: HelpingMapper) {
mapper <<< self.id <-- "cat_id"
mapper <<< self.friendName <-- "friend.name"
}
}
```
This is Good when deserializing jsons.
```swift
let jsonString = "{\"cat_id\":12345,\"myname\":\"Kitty\",\"friend\":{\"name\":\"Lily\"}}"
if let cat = Cat.deserialize(from: jsonString) {
print(cat.myname)
print(cat.friendName)
}
```
But when calls toJsonString() it prints:
```json
"{\"cat_id\":12345,\"myname\":\"Kitty\",\"name\":\"Lily\"}"
```
Witch "Lily" should be under a "friend" sub json
This issue is **not** same as #111
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing toJsonString() and the HelpingMapper mapping shown in the Cat example, then run the deserialization and serialization demo from the issue. The completed behavior should preserve the mapped friend.name value under a friend JSON object rather than emitting a top-level name field.
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