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

Add serialisation compatibility of TimeSpan and DateTime #16205

Merged
merged 52 commits into from
Jun 11, 2024

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented May 31, 2024

fixes #16203

@hyzx86 hyzx86 marked this pull request as ready for review May 31, 2024 12:42
@hyzx86
Copy link
Contributor Author

hyzx86 commented May 31, 2024

Adding test recipes causes database concurrency conflicts, remove test recipes

@hyzx86
Copy link
Contributor Author

hyzx86 commented May 31, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented May 31, 2024

Walkthrough

The changes introduce a new TimeSpanConverter to handle custom JSON serialization and deserialization for TimeSpan objects in the OrchardCore framework. This converter is added to the JOptions class to ensure TimeSpan fields are correctly processed. Additionally, a new test method TimeFieldTests has been added to validate the serialization and deserialization of TimeField objects, addressing a specific issue where TimeField could not be deserialized from JSON.

Changes

File(s) Change Summary
src/OrchardCore/OrchardCore.Abstractions/Json/JOptions.cs Added TimeSpanConverter to the list of converters in the JOptions class.
src/OrchardCore/OrchardCore.Abstractions/Json/Serialization/TimeSpanConverter.cs Implemented TimeSpanConverter class for custom JSON serialization and deserialization of TimeSpan objects.
test/OrchardCore.Tests/Data/ContentItemTests.cs Added TimeFieldTests method to test the serialization of TimeField objects.

Sequence Diagram(s) (Beta)

No sequence diagrams are included because the changes are straightforward and primarily involve adding a new converter and a test method.

Assessment against linked issues

Objective Addressed Explanation
Ensure TimeField can be deserialized from JSON (#16203)
Add test to validate TimeField deserialization (#16203)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hyzx86
Copy link
Contributor Author

hyzx86 commented May 31, 2024

Hi @Piedone , this PR is ready for review :)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

hyzx86 and others added 2 commits May 31, 2024 21:10
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@hyzx86 hyzx86 changed the title Fix TimeFiled Deserialisation Add compatibility between TimeSpan and DateTime serialisation May 31, 2024
@hyzx86 hyzx86 changed the title Add compatibility between TimeSpan and DateTime serialisation Add serialisation compatibility of TimeSpan and DateTime May 31, 2024
@hyzx86
Copy link
Contributor Author

hyzx86 commented May 31, 2024

I also added serialisation compatibility for DateTime
However, the issue of regional culture may require some discussion

Because some of the calls are extension methods, we may need to tweak some existing code if we use dynamic specification.

if (((JsonObject)contentItem.Content)[fieldDefinition.ContentTypePartDefinition.Name] is not JsonObject jPart ||
jPart[fieldDefinition.Name] is not JsonObject jField)
{
return null;
}
return jField.ToObject<TField>();

/cc @MikeAlhayek @Piedone

@Piedone
Copy link
Member

Piedone commented May 31, 2024

Don't the fields already store the date/timestamps in a culture-agnostic way? They really should.

Maybe then it needs to check for TField being e.g. TimeField (or have separate overloads for these)?

@hyzx86
Copy link
Contributor Author

hyzx86 commented May 31, 2024

Yes. Now it looks like there's a problem with how to apply the region option, and it's the fact that the region option is specified here that's causing the rest of the unit test to crash!

@hishamco
Copy link
Member

hishamco commented Jun 9, 2024

@hyzx86 please second time resolve the conversation by clicking the button, so this will indicate that you reacted to the changes, is there anything remaining in this PR?

hyzx86 and others added 2 commits June 10, 2024 22:57
Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
@hyzx86 hyzx86 requested a review from hishamco June 10, 2024 14:58
@hishamco
Copy link
Member

@hyzx86 please address my last comment then I can merge

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 11, 2024

@hyzx86 please address my last comment then I can merge

Is that all right? @hishamco

hyzx86 and others added 3 commits June 11, 2024 14:04
…teTimeJsonConverter.cs

Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
@hishamco hishamco merged commit 3d3f172 into OrchardCMS:main Jun 11, 2024
14 checks passed
@hishamco
Copy link
Member

Thanks again @hyzx86

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 11, 2024

oh ... It's not finished yet, I realised we didn't do error handling, I added them.

hyzx86@7c4c1d0

@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 11, 2024

I've resubmitted a patch here to ensure that the wrong time format is recognised #16288

microposmp pushed a commit to microposmp/OrchardCore that referenced this pull request Jun 13, 2024
…16205)

Co-authored-by: Mike Alhayek <mike@crestapps.com>
Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
sebastienros pushed a commit that referenced this pull request Jun 13, 2024
#16274)

* Saving workflow fails

* Fix solution build file references (#16269)

* Remove Gitter references (#16270)

* Add serialisation compatibility of TimeSpan and DateTime  (#16205)

Co-authored-by: Mike Alhayek <mike@crestapps.com>
Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>

* Update Azure.Identity 1.11.4 (#16286)

* Add rounding.

---------

Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
Co-authored-by: Tony Han <huarui2219@qq.com>
Co-authored-by: Mike Alhayek <mike@crestapps.com>
Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
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.

TimeField , DateTimeField and DateField cannot be deserialised from Json
5 participants