-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] AOT safe enums serialization #16386
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
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enables AOT-safe enum serialization in the BiDi JSON serialization context by adding the UseStringEnumConverter
option to the JSON source generation configuration.
- Adds
JsonSourceGenerationOptions
attribute withUseStringEnumConverter = true
to enable string-based enum serialization - Ensures compatibility with .NET's Native AOT compilation for BiDi communication
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@RenderMichael do you know? (hard to debug) |
PR Code Suggestions ✨Explore these optional code suggestions:
|
Oh, it is still not correct. We have added global converter: new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) As soon as I remove this converter, then enums are converted as PascalCase. Will do CamelCase custom converter. |
I added |
Yes, this is AOT-safe and the preferred way of enabling this behavior.
These enums are already known to the serializer context because they are properties of types which are known to the serializer context. |
I much prefer this approach for all converter attributes, because we are safer to use multiple serializer contexts, and let users serialize the types with their own serializer. What do you think @nvborisenko ? Not in this PR, either way, but want to know your opinion. |
Absolutely, we already discussed that DTO objects might be reused across modules, even across extension modules (like #15329). Seems we are on the way to apply converters via attributes. Not in this PR, but yes: design approach is approved. Thanks for your help. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice update!
User description
Contributes to #14480
💥 What does this PR do?
Generated json serialization now treats enums? Meaning AOT safe?
🔄 Types of changes
PR Type
Bug fix
Description
Enable AOT-safe enum serialization in BiDi JSON context
Add UseStringEnumConverter option for string-based enum handling
Diagram Walkthrough
File Walkthrough
BiDiJsonSerializerContext.cs
Add AOT-safe enum serialization configuration
dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs
UseStringEnumConverter = true