When I add a custom JsonConverter to multiple properties, only the callback for the last property is invoked. It is invoked for each property with a custom JsonConverter.
Reproduction Steps
Create two classes C1 and C2
Assign a custom JsonConverter to each of these classes
Create another class named Test containing a property of each C1 and C2
Register a callback to JsonSchemaExporterOptions.TransformSchemaNode
Log the context.PropertyInfo and context.TypeInfo
Types
[JsonConverter(typeof(C1JsonConverter))]
public class C1 { }
[JsonConverter(typeof(C2JsonConverter))]
public class C2 { }
public class Test
{
public C1 C1 { get; set; }
public C2 C2 { get; set; }
}
Converters
public class C1JsonConverter:JsonConverter<C1>
{
public override C1? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
new();
public override void Write(Utf8JsonWriter writer, C1 value, JsonSerializerOptions options) =>
writer.WriteStringValue("C1");
}
public class C2JsonConverter:JsonConverter<C2>
{
public override C2? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
new();
public override void Write(Utf8JsonWriter writer, C2 value, JsonSerializerOptions options) =>
writer.WriteStringValue("C2");
}
Description
I expect JsonSchemaExporterOptions.TransformSchemaNode to be invoked once for each property of a class. The
JsonSchemaExporterContext
parameter should be set to the property.When I add a custom
JsonConverter
to multiple properties, only the callback for the last property is invoked. It is invoked for each property with a customJsonConverter
.Reproduction Steps
C1
andC2
JsonConverter
to each of these classesTest
containing a property of eachC1
andC2
JsonSchemaExporterOptions.TransformSchemaNode
context.PropertyInfo
andcontext.TypeInfo
Types
Converters
Main
Expected behavior
I expect to see one console message for each property:
Actual behavior
The callback is invoked two times with the context of property
Test.C2
:Removing one or both of the custom
JsonConverters
will fix this issue.Regression?
No response
Known Workarounds
No response
Configuration
Other information
No response