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

[Feature]: Extend JSValueDecoder/JSValueDecoder with More Control over Dates, Data, and Numbers #7576

Closed
1 of 3 tasks
grantjbutler opened this issue Jul 22, 2024 · 3 comments
Labels
type: feature request A new feature, enhancement, or improvement

Comments

@grantjbutler
Copy link

Description

It'd be great if we had more control over how dates, data, and non-confirming floats were encoded and decoded.

Platforms

  • iOS
  • Android
  • Web

Request or proposed solution

JSONEncoder/JSONDecoder from Foundation allow you to configure the object with a strategy as to how to encode or decode dates, data, and non-conforming floating point numbers. This is most helpful when working with dates, as there are many ways to encode or decode dates from some structured data (it could be formatted as a UNIX timestamp in seconds or milliseconds, or be formatted as an ISO 8601 string).

It'd be great if JSValueDecoder and JSValueEncoder supported some or all of the various ways that JSONDecoder and JSONEncoder can be configured to transform these various values.

Alternatives

No response

Additional Information

No response

@Steven0351
Copy link
Member

Steven0351 commented Sep 6, 2024

Data isn't actually a valid type to pass through to a WKWebView. As far as non-conforming floats, everything actually passes over the bridge as an NSNumber, so I'm not 100% sure anything there could happen. I have, however, opened PR #7647 to address Date and URL issues.

Edit: Data encoding strategy definitely makes sense, my brain needed some more time to think about it.
Edit 2: That PR should address all the points raised in this issue now.

@Steven0351
Copy link
Member

Thinking more about the non-conforming float strategies, I would believe today those are not throwing at all because Infinity, -Infinity, and NaN are valid NSNumbers. We would need our own strategy that allows for not throwing or converting to a string.

Copy link

ionitron-bot bot commented Oct 12, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature request A new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

3 participants