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

TransformSchemaNode & JsonConverter #111122

Closed
vsfeedback opened this issue Jan 6, 2025 · 2 comments
Closed

TransformSchemaNode & JsonConverter #111122

vsfeedback opened this issue Jan 6, 2025 · 2 comments

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
The TransformSchemaNode callback is called with wrong information in both parameters when more than one property uses a JsonConverter.

public sealed class TheConverter : JsonConverter<int>
{
    public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotImplementedException();
    public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options) => throw new NotImplementedException();
}

public sealed class TheClass
{
    [JsonConverter(typeof(TheConverter))] public int Prop1 { get; set; }
    [JsonConverter(typeof(TheConverter))] public int Prop2 { get; set; }
}

internal class Program
{
    static void Main()
    {
        var jsonSchemaExporterOptions = new JsonSchemaExporterOptions
        {
            TransformSchemaNode = (context, schema) =>
            {
                Console.WriteLine($"path: $/{string. Join("/", context. Path.ToArray())}/, property name: {context. PropertyInfo?. Name}");
                return schema;
            },
        };
        var options = JsonSerializerOptions.Default;
        var schema = options. GetJsonSchemaAsNode(typeof(TheClass), jsonSchemaExporterOptions);
        Console.WriteLine(schema. ToString());
    }
}

Output is:

path: $/properties/Prop2/, property name: Prop2
path: $/properties/Prop2/, property name: Prop2
path: $//, property name:
{
  "type": [
    "object",
    "null"
  ],
  "properties": {
    "Prop1": true,
    "Prop2": true
  }
}

Output should be:

path: $/properties/Prop1/, property name: Prop1
path: $/properties/Prop2/, property name: Prop2
...

Original Comments

Feedback Bot on 19/11/2024, 03:31 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 6, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@eiriktsarpalis
Copy link
Member

Duplicate of #109868

@eiriktsarpalis eiriktsarpalis marked this as a duplicate of #109868 Jan 7, 2025
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants