-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
ReadableArray and ReadableMap do not support Long (int64) #12506
Comments
I'm not certain but believe this could be because JS doesn't have longs yet (64-bit types are coming) and it would be deceiving to provide |
Interesting. I still don't quite understand the additions of the ReadableMap and ReadableArray, since Objective C just uses built in types. Is this just due to JavaScriptCore functionality, no comparable functionality in native Java? |
I'm not really sure, I imagine the fact that the authors were different people at different times has something to do with the discrepancy. The unified C++ bridge is coming which should clear away these differences in C++ if you prefer to program at that level. |
There was previously conversation in #9685
If a programmer knows it's sending a large integer value, there's no choice other than using this forced casting code, which in my opinion leads to confusion rather than thinking about consequences of double -> long. The timestamps in Android/Java for example are mostly represented as longs since they're passed as milliseconds, using set/getLong would be the most natural for these.
I think this is the real reason. Before exposing the method, we should make sure the types work correctly without potentially losing precision or overflowing while crossing Java/JS bridges.
That's interesting. I'm also curious what Java lacks then.
Unrelated to this issue, but is there any doc about this? |
I think the source code is the best place to look, it's already in master. |
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally! If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution. |
@MattFoley maybe a solution for this. double value = readableMap.getDouble(key);
try {
// long support && float check
if (value > Integer.MAX_VALUE && value % 1 == 0) {
long cv = (long) value;
// use the long value
}
} catch (Exception e) {
// use raw value
} |
Description
Attempting to consume an API that serves long values in some cases via JSON. When passing from JS to Native Java code on Android, there is no getLong functionality on ReadableArray and ReadableMap.
Reproduction
Simply pass a value greater than MAX_INT to Java from JS via a ReadableArray or ReadableMap.
Attempt to use getInt and see exception:
Attempt to use getString and see exception:
Solution
This feels magical and bad, but this works for the moment.
Current workaround:
Better solution would be to add getLong, or some other function able to fetch long values.
Additional Information
The text was updated successfully, but these errors were encountered: