-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix numeric enum deserialization #24394
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
Changes from all commits
b0ecd31
f6f69bc
ab54d9a
8ddebe6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| if (utf8JsonReader.TokenType == JsonTokenType.Null) | ||
| {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}null); | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| else | ||
| { | ||
| string {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}RawValue = utf8JsonReader.{{>EnumJsonReaderMethod}}().ToString(System.Globalization.CultureInfo.InvariantCulture); | ||
| {{classname}}.{{{datatypeWithEnum}}}? {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}Value = {{classname}}.{{{datatypeWithEnum}}}FromStringOrDefault({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}RawValue); | ||
| if ({{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}Value == null) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: The throw new JsonException() for unrecognized numeric enum values contradicts the PR's stated behavior. For nullable enums, unknown values should be deserialized as null (not throw). For non-nullable enums, unknown values should leave the option unset. Either restore the nullable-aware branching from the old template, or update the PR description to reflect the breaking change. Prompt for AI agents |
||
| throw new JsonException(); | ||
| {{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}Value); | ||
| } | ||
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.
P2: Unknown nullable string enum values now raise
JsonExceptioninstead of deserializing as null, regressing the existing inner-enum behavior and making this path inconsistent with the nullable handling described for numeric enums. The null result should be assigned to the optional property rather than treated as an exception for nullable fields.Prompt for AI agents