I think you should do something like this:
First add annotation for Company property and create a helper model it
public class ResponseModel
{
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("company")] // and specify possible list of types as string or CompanyModel
[JsonConverter(typeof(CompanyJsonConverter))] // add this line
public string Company { get; set; }
}
public class CompanyHelperModel
{
public string name { get; set; }
}
Then create the actual converter class (I sadly cannot test it right now, but the logic should be correct):
public class CompanyJsonConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
// don't care
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.ValueType == typeof(string)) return reader.ReadAsString();
return JsonConvert.DeserializeObject<CompanyHelperModel>(reader.ReadAsString()).name;
}
public override bool CanConvert(Type objectType)
{
return true;
}
}
And that's it! I assumed that you need only to read it, not write it.