I need Asp.net to deserialize an object's property with a specific derived class.
According to Newtonsoft's documentation, I should be able to change the JsonContract for the base class Equipment.Shared.Model.SimCard. https://www.newtonsoft.com/json/help/html/ContractResolver.htm
Class Transmitter has a property (Simcard) Equipment.Shared.Model.SimCard, but I need to have it deserialized as TlsModel.SimCard, otherwise TlsModel.SimCard properties are discarded during deserialization.
public class TlsModelContractResolver : DefaultContractResolver
{
protected override JsonContract CreateContract(Type objectType)
{
JsonContract contract = base.CreateContract(objectType);
if (objectType == typeof(Equipment.Shared.Model.SimCard) )
{
contract.CreatedType = typeof(SimCard);
Console.WriteLine("Simcard CreateType is updated");
}
return contract;
}
}
At the first deserialization, I have the log line 'Simcard CreateType is updated', so my contract deseralizer is taken into account.
But transmitter.SimCard is still a Equipment.Shared.Model.SimCard and not TlsModel.SimCard as I excptected.
Did I miss something ?