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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6320] Codable JSONEncoding/JSONDecoding bool in both directions not possible #4061

Closed
swift-ci opened this issue Nov 7, 2017 · 4 comments

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2017

Previous ID SR-6320
Radar None
Original Reporter leonidas_o (JIRA User)
Type Bug
Status Closed
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Codable
Assignee None
Priority Medium

md5: 7cb662cc5f05588a06c7c5cae24fea9a

Issue Description:

Codable - JSONEncoder()/ JSONDecoder()

Using JSONEncoder() booleans are encoded to a Number 0/1. This JSON is used to be indexed inside elasticsearch.

When fetching this data from elasticsearch, the struct's properties are defined as booleans, here JSONDecoder() is throwing an error:

"Expected to decode Bool but found a number instead."

This doesn't make much sense, as you only can go in one direction. You are able to encode (true/false) -> (0/1) but when trying to go back (0/1) -> (true/false) is not possible, you get an error.

@belkadan
Copy link

belkadan commented Nov 7, 2017

Can you attach a self-contained example? We're definitely supposed to be encoding booleans (not NSNumbers) as true/false.

@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 7, 2017

Comment by Leo (JIRA)

hmm yeah I think the issue is in one of vapor's packages. I will investigate that and let you know as soon as I found out.

@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 8, 2017

Comment by Leo (JIRA)

@belkadan okay it was on vapors side, sorry for opening it here to quickly, I will close the issue.

@swift-ci
Copy link
Contributor Author

swift-ci commented Nov 8, 2017

Comment by Leo (JIRA)

Not a swift Codable issue. Was inside a wrapper from swift vapor.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants