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

SWIFT-325 BSON init int64 inconsistency. (Not a bug) #89

Open
icyield opened this issue Nov 14, 2022 · 1 comment
Open

SWIFT-325 BSON init int64 inconsistency. (Not a bug) #89

icyield opened this issue Nov 14, 2022 · 1 comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system

Comments

@icyield
Copy link

icyield commented Nov 14, 2022

When initing a BSON from a literal it is an int64 by default, but is easy to change (.int32(5)). However when using JSON the "default" type is int32.

Is there a method to force JSON to give int64 as the default type for small value ints?

We have

/// Initialize a BSON from an integer. On 64-bit systems, this will result in an .int64. On 32-bit systems,
/// this will result in an .int32.
public init(integerLiteral value: Int) {
self.init(value)
}

But for JSON we have
// Spec requires that we try int32, try int64, then try double for decoding numbers
if let int32 = try Int32(fromExtJSON: json, keyPath: keyPath) {
self = int32.bson
return
}

@icyield icyield added the bug Something isn't working label Nov 14, 2022
@bajanam bajanam removed bug Something isn't working triage labels Nov 15, 2022
@isabelatkinson
Copy link
Contributor

Hi @icyield - unfortunately the extended JSON spec requires us to try to fit numeric values into the smallest type possible (see here), so we cannot default numbers to 64-bit integers. If you'd like to force your JSON to decode numbers to 64-bit integers, one option is to decode to a struct that contains Int64s. Otherwise, you may need to update your fields manually.

SWIFT-325 covers adding number encoding/decoding strategies, and I've added a comment for us to consider adding strategies such as the one you've requested to our ExtendedJSONDecoder as well. Feel free to follow that ticket for updates on this work.

@bajanam bajanam added the tracked-in-jira Ticket filed in Mongo's Jira system label Dec 13, 2022
@bajanam bajanam changed the title BSON init int64 inconsistency. (Not a bug) SWIFT-325 BSON init int64 inconsistency. (Not a bug) Dec 13, 2022
@isabelatkinson isabelatkinson removed their assignment Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system
Projects
None yet
Development

No branches or pull requests

3 participants