Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON Parsing Issues in CodableTransform #1103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Woollim
Copy link

@Woollim Woollim commented Aug 4, 2020

Why

  1. Problem occurred when trying to parse the JSON Array.

釀夅叧釀忈叧釀呩叺釂剦釁a喓 2020-08-04 釀嬦叐釀掅叜 6 00 47

let json = ["array_value": [1, 2, 3, 4, 5]]
// not working! 馃檧
self.array = try map.value("array_value", using: CodableTransform<[Int]>())
  1. Problem occurred when trying to parse single JSON value using Key Path.

釀夅叧釀忈叧釀呩叺釂剦釁a喓 2020-08-04 釀嬦叐釀掅叜 6 00 36

let json = ["int_value": 1]
// not working too! 馃檧
self.value = try map.value("int_value", using: CodableTransform<Int>())

What

  1. Fix transformFromJSON function logic in CodableTransform.swift
  2. Add test case for JSON Array, Single Value From JSON Object parsing

}
return try? JSONDecoder().decode(T.self, from: data)
} else {
guard let data = try? JSONSerialization.data(withJSONObject: ["value": item], options: []) else {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote Single Value parsing code by referring to Moya's code.
Link: Moya/Response.swift/Line-167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant