Open
Description
Description
Json source generator generates invalid code when a property name is a keyword, like @event
Reproduction Steps
- create a class that has a property call @event
- create a JsonSerializerContext class that references above class
- build and notice compiler errors in generated code
public class ClickEvent {
public required string @event { get; set; }
}
[JsonSerializable(typeof(ClickEvent))]
public partial class ClientEventContext : JsonSerializerContext { }
Expected behavior
generated code does not cause compile errors
Actual behavior
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::TwentyTenSolutions.ContentManagement.Editing.ViewModels.ClickEvent> Create_ClickEvent(global::System.Text.Json.JsonSerializerOptions options)
{
if (!TryGetTypeInfoForRuntimeCustomConverter<global::TwentyTenSolutions.ContentManagement.Editing.ViewModels.ClickEvent>(options, out global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::TwentyTenSolutions.ContentManagement.Editing.ViewModels.ClickEvent> jsonTypeInfo))
{
var objectInfo = new global::System.Text.Json.Serialization.Metadata.JsonObjectInfoValues<global::TwentyTenSolutions.ContentManagement.Editing.ViewModels.ClickEvent>
{
ObjectCreator = null,
ObjectWithParameterizedConstructorCreator = static args => new global::TwentyTenSolutions.ContentManagement.Editing.ViewModels.ClickEvent(){ event = (string)args[0] },
PropertyMetadataInitializer = _ => ClickEventPropInit(options),
ConstructorParameterMetadataInitializer = ClickEventCtorParamInit,
SerializeHandler = ClickEventSerializeHandler
};
jsonTypeInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::TwentyTenSolutions.ContentManagement.Editing.ViewModels.ClickEvent>(options, objectInfo);
jsonTypeInfo.NumberHandling = null;
}
jsonTypeInfo.OriginatingResolver = this;
return jsonTypeInfo;
}
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response