I have the following classes
class Configuration
{
public IConverter converter { get; set; }
}
public class HtmlConverter : IConverter
{
public string Convert()
{
return "HTML Convertter";
}
}
public class JsonConverter : IConverter
{
public string Convert()
{
return "json Convertter";
}
}
public interface IConverter
{
string Convert();
}
and myjson file is
{
"Configuration": {
"Converter": "HtmlConverter"
}
}
from the JSON file, I want to create the Configuration object.
in json file if converter is set to "HtmlConverter" then the HtmlConvert object should be created and if "JsonConverter" is set then JsonConverter object should be created.
Configuration config = JsonConvert.DeserializeObject<Configuration>(jsonString);
Configuration) only has a property "Converter" (which doesn't exist in your JSON's root object).