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

fix(package_info_plus): data serialization converts installTime to String instead of DateTime #3464

Merged
merged 8 commits into from
Feb 6, 2025

Conversation

dharambudh1
Copy link
Contributor

@dharambudh1 dharambudh1 commented Feb 5, 2025

This commit addresses an issue where the installTime was not being properly serialized due to being a DateTime object. When attempting to convert the object to JSON, an error occurred as DateTime is not natively encodable. The installTime is now explicitly converted to a string before being included in the JSON, preventing the serialization failure.

Description

This PR addresses an issue where the installTime (a DateTime object) was not being properly serialized into JSON, causing errors when trying to encode the object. The installTime is now explicitly converted to a string before it’s included in the JSON, ensuring compatibility with the encoding process. This change prevents the "Converting object to an encodable object failed" error and allows for correct JSON handling.

Related Issues

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

This commit addresses an issue where the `installTime` was not being properly serialized due to being a `DateTime` object. When attempting to convert the object to JSON, an error occurred as `DateTime` is not natively encodable. The `installTime` is now explicitly converted to a string before being included in the JSON, preventing the serialization failure.
@miquelbeltran
Copy link
Member

miquelbeltran commented Feb 5, 2025

Thanks for catching this up. It is probably better to use toIso8601String() instead.

@miquelbeltran
Copy link
Member

Seems that some tests need to be fixed as well.

@miquelbeltran miquelbeltran changed the title fix: Convert DateTime to string to resolve JSON serialization error fix(package_info_plus): data serialization converts installTime to String instead of DateTime Feb 5, 2025
Updated the 'installTime' field to be converted to ISO 8601 string format instead of default string representation. This change ensures consistency in date formatting for better compatibility and parsing.
@dharambudh1
Copy link
Contributor Author

@miquelbeltran, I updated installTime format to ISO 8601 string for consistency (hope this helps with parsing and compatibility).

@miquelbeltran
Copy link
Member

Github actions is showings lots of errors, please ensure that the project has no analysis errors and all tests pass

dharambudh1 and others added 4 commits February 5, 2025 23:27
- Updated the 'installTime' field to use a fallback empty string if 'installTime' is null, ensuring no null values are passed.
- This change improves stability by preventing potential null-related errors.
- Refactored the conditional check for 'installTime' to improve readability and maintain consistent code style.
- The fallback to an empty string is maintained if 'installTime' is null.
@dharambudh1
Copy link
Contributor Author

@miquelbeltran, I'm almost there, but one of the GitHub Actions is failing. All tests work fine locally, and I believe the failing test isn't critical. Can we move ahead? Could you review my PR and merge it?

@vbuberen
Copy link
Collaborator

vbuberen commented Feb 6, 2025

Don't worry about failing Android integration tests - they are flaky and having time outs not because of your changes.

Copy link
Member

@miquelbeltran miquelbeltran left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the CI issues!

@miquelbeltran
Copy link
Member

miquelbeltran commented Feb 6, 2025

I changed the conditional access, since the variable is already checked if it was null.

I've added a test to check JSON conversion of the Data payload to ensure this doesn't break in the future.

@miquelbeltran miquelbeltran merged commit aa10ce7 into fluttercommunity:main Feb 6, 2025
19 of 21 checks passed
@dharambudh1
Copy link
Contributor Author

dharambudh1 commented Feb 6, 2025

@miquelbeltran & @vbuberen, thanks so much for considering, reviewing, and merging the PR! I really appreciate the time and effort put into it. Looking forward to more collaborations!

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.

[Bug]: Unhandled Exception: Converting object to an encodable object failed: Instance of 'DateTime'
3 participants