I have a weird issue and am confused. I have 3 class:
public class ProductInfo
{
public List<PartInfo> PartInfos { get; set; }
public string Name { get; set; }
}
public class SubProductInfo : PartInfo
{
public ProductInfo ProductInfo { get; set; }
}
public class PartInfo
{
public string Name { get; set; }
public string Desc { get; set; }
}
I have some information for industrial products. each product has some part and some sub product. for each product I have an object from type 'ProductInfo'. for each part related to this product I have an object of type 'PartInfo' and for each sub product related to this product I have an object of type 'SubProductInfo'. this 'ProductInfo' object serialized with 'JsonConvert.SerializeObject' method. Example for serialized information:
{"PartInfos":[{"Name":"Part1","Desc":"Part1's Desc"},{"ProductInfo":{"PartInfos":[{"Name":"SubProduct1's Part1","Desc":"SubProduct1's Part1 desc"},{"Name":"SubProduct1's Part2","Desc":"SubProduct1's Part2 desc"}],"Name":"SubProduct1"},"Name":"SubProduct1 Details","Desc":"SubProduct1's Desc"}],"Name":"Product1"}
now I want to deserialize these JSONs to orginal object. I used:
JsonConvert.DeserializeObject<ProductInfo>(serializedObject)
but in deserialization 'SubProductInfo' objects will deserialize to 'PartInfo' objects. how I can deserialize these JSONs to Exactly orginal objects?
>()`.
– MakePeaceGreatAgain Apr 06 '21 at 13:37