So i have WeaponStats class that contains one of classes that inherit from IDamageType. Fire is empty bacause i didn't receive anything back from game designer and its still empty. But i can add anything to code. When i try to Serialize it, it doesn't get any thing back to deserialize to. And my question is what is a better way to Serialize and Deserialize Fire and any similar class? I Edited to add new information. JsonCalculator calculates needed stats and returns them. And Staff.json is an exemplar of json i used for deserelialization. Last code sample is what i get when i serialize WeaponStats with Fire.
public class WeaponStats : IEquipmentStats { public int Damage; public IDamageType DamageType; public int Range; public int ActionPointsCost; public float CritDamageChance; public float CritDamage; public int SkillCooldown; public int ElementalDamage; } public interface IDamageType { } public class Fire : IDamageType { } public static class JSONCalculator<T> where T : class, IEquipmentStats { static string path = @"Assets\_Project\Scripts\Units\Systems\Equipment\Exemplars\"; public static T GetEquipmentStats(string fileName,int level) { string newPath = Path.Combine(Environment.CurrentDirectory, (path + fileName+".json")); string jsonString = File.ReadAllText(newPath); Dictionary<string, T> results = JsonConvert.DeserializeObject<Dictionary<string,T>>(jsonString);// bug string levelStr = "level"; switch (level) { case 0: levelStr += "Zero"; break; case 1: levelStr += "One"; break; case 2: levelStr += "Two"; break; case 3: levelStr += "Three"; break; } return results[levelStr]; } } Staff.json
{ "levelZero": { "Damage": 10, "DamageType": {}, "Range": 4, "ActionPointsCost": 2, "CritDamageChance": 5, "CritDamage": 150, "SkillCooldown": 2, "ElementalDamage": 2 }, "levelOne": { "Damage": 20, "DamageType": {}, "Range": 4, "ActionPointsCost": 2, "CritDamageChance": 5, "CritDamage": 150, "SkillCooldown": 2, "ElementalDamage": 2 }, "levelTwo": { "Damage": 30, "DamageType": {}, "Range": 4, "ActionPointsCost": 2, "CritDamageChance": 5, "CritDamage": 150, "SkillCooldown": 2, "ElementalDamage": 2 }, "levelThree": { "Damage": 40, "DamageType": {}, "Range": 4, "ActionPointsCost": 2, "CritDamageChance": 5, "CritDamage": 150, "SkillCooldown": 2, "ElementalDamage": 2 } } {\"Damage\":0,\"DamageType\":{},\"Range\":0,\"ActionPointsCost\":0,\"CritDamageChance\":0.0,\"CritDamage\":0.0,\"SkillCooldown\":0,\"ElementalDamage\":0}" public interface IEquipmentStats { }