Hello i was wondering if you can manage to to deserialize a json that has its Discriminator outside the Discriminated object:
The below example works
public class Parent{
Child childField{get;set;}
}
[JsonConverter(typeof(JsonSubTypes),CHILDTYPE)]
[JsonSubTypes.KnownSubTypes(typeof(Child1),CTYPE.Child1)]
[JsonSubTypes.KnownSubTypes(typeof(Child2),CTYPE.Child2)]
public abstract class Child{
public enum Discriminator{
Child1=0,
Child2=1
}
private const string CHILDTYPE="childType"
[JsonProperty(CHILDTYPE)]
public abstract Discriminator Kind{get;}
}
public class Child1:Child{
public int Value{get;set;}
public override Kind=>Discriminator.Child1;
}
public class Child2:Child{
public bool Value{get;set;}
public override Kind=>Discriminator.Child2;
}
What i want to achieve :
Could you move the Kind field to the parent object and decorate the parent so that it uses the Kind field to discriminate the childField ?
Detailed question here
Long story short
Can i accomodate from this json:
{
"childField":{ "Kind":3}
}
To this json:
{
"Kind":3,
"childField":{}
}
Hello i was wondering if you can manage to to deserialize a json that has its
Discriminatoroutside the Discriminated object:The below example works
What i want to achieve :
Could you move the
Kindfield to the parent object and decorate the parent so that it uses theKindfield to discriminate thechildField?Detailed question here
Long story short
Can i accomodate from this json:
{ "childField":{ "Kind":3} }To this json:
{ "Kind":3, "childField":{} }