You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Assembly registration, the order in which class are handle has an effect in the result.
If you take the exemple that follow, AFoo declaration is handled before Foo, so the serializer will register without discriminator convention.
Then when Foo is handled, it won't override AFoo.
As a result you get an error when trying to deserialize.
If I simply move AFoo declaration after Foo declaration, then it work properly.
// See https://aka.ms/new-console-template for more informationusingSystem.Text.Json;usingDahomey.Json;usingDahomey.Json.Attributes;varjson=""" {"MyProp": { "$type": "Foo", "Id": 1}}""";varjsonSerializerOptions=newJsonSerializerOptions();jsonSerializerOptions.SetupExtensions();varregistry=jsonSerializerOptions.GetDiscriminatorConventionRegistry();registry.RegisterAssembly(typeof(Encapsulator).Assembly);varitem=JsonSerializer.Deserialize<Encapsulator>(json,jsonSerializerOptions);Console.WriteLine(item);publicclassEncapsulator{publicAFooMyProp{get;set;}}publicabstractclassAFoo{publicintId{get;set;}}[JsonDiscriminator("Foo")]publicclassFoo:AFoo{}
The text was updated successfully, but these errors were encountered:
When using Assembly registration, the order in which class are handle has an effect in the result.
If you take the exemple that follow, AFoo declaration is handled before Foo, so the serializer will register without discriminator convention.
Then when Foo is handled, it won't override AFoo.
As a result you get an error when trying to deserialize.
If I simply move AFoo declaration after Foo declaration, then it work properly.
The text was updated successfully, but these errors were encountered: