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 JsonStringEnumConverter to KnownConverters #16913

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/OrchardCore/OrchardCore.Abstractions/Json/JOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class JOptions
PathStringJsonConverter.Instance,
TimeSpanJsonConverter.Instance,
DateTimeJsonConverter.Instance,
new JsonStringEnumConverter()
Copy link
Member

Choose a reason for hiding this comment

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

First, you should create a static instance of this converter and the static instance. This will fix the issue. However, this will change the behavior of how we store enum moving forward from int to string.

But it could increase the size of data being transmitted from and to the server. Personally, I am okay with storing strings instead of int since this will ensure we don't have enum problem if someone adds a new enum value in position other than the end of the enum.

I would also document this change in the release notes to ensure people are aware of this change.

@sebastienros thought on this global behavior?

Copy link
Member

Choose a reason for hiding this comment

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

Related discussion #13154

Copy link
Member

Choose a reason for hiding this comment

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

If we don't own the converter it's fine to not have the Instance property.
Does it work with both int and string as input, to be sure it's not breaking any.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't own the converter

Does it work with both int and string as input, to be sure it's not breaking any.

It should, but I will try another test

Copy link
Member

Choose a reason for hiding this comment

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

@sebastienros yes it works with both int and string. However, it will write string moving forward and not int. It won't break anyone but will change the behavior.

];

public static readonly JsonSerializerOptions Base = new()
Expand Down