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
The System.Text.Json source generator doesn't populate JsonPropertyInfo.AttributeProvider
metadata.
#100095
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
@eiriktsarpalis I'm interested how this could affect a JSON Schema representation. Where does this come from? |
@gregsdennis We want to be able to extract a JSON schema from the contract as specified in |
Happy to talk about this more offline if you have the time. |
Reopening, since apparently #100173 doesn't fully address the issue for the case of trimmed/Native AOT applications. The fact that it's using delayed One potential solution (already trialed in typeshape-csharp) is adding a delayed factory for namespace System.Text.Json.Serialization.Metadata;
public partial class JsonPropertyInfoValues<T>
{
public Func<ICustomAttributeProvider>? CustomAttributeProviderFactory { get; init; }
} which would be populated by the source generator as follows: new JsonPropertyInfoValues<string>
{
PropertyName = "Name",
CustomAttributeProviderFactory = static () => typeof(Person).GetProperty("Name"),
};
public record Person(string Name); This should provide the linker with sufficient hints so that metadata for the particular properties will not be trimmed. Given that this necessarily results in some reflection components being rooted by the source generator, we might additionally consider an opt-in flag in namespace System.Text.Json.Serialization;
public partial class JsonSourceGenerationOptionsAttribute
{
public bool GenerateAttributeProviderFactories { get; set; } = null;
} |
Superseded by #102078. |
The
JsonPropertyInfo.AttributeProvider
property isn't being populated by the source generator, making it impossible to resolve additional attributes fromJsonPropertyInfo
instances. This can create issues when mapping contract metadata to richer representations such as JSON schema (e.g. resolvingDescriptionAttribute
).cc @captainsafia @stephentoub
The text was updated successfully, but these errors were encountered: