I have some objects:
public class MyObject
{
public MyField Field { get; set; }
}
public class MyField
{
[JsonProperty]
public Entity MyEntity { get; set; }
public IEntity IMyEntity { get; set; }
}
public interface IEntity
{
string MyStr { get; }
}
public class Entity : IEntity
{
}
Then I am trying to do something like
JsonConvert.DeserializeObject<MyObject>(myObjStr);
Which throws an error similar to
Could not create an instance of type MyObject... Type is an interface or abstract class and cannot be instantiated. Path 'MyField.IMyEntity.MyInt'
I can't change the field or entity, as that is in another group's codebase. The MyObject class is in mine. Is there a way to deserialize this object? I've tried a few things with JsonSerializerSettings here JSON.NET - how to deserialize collection of interface-instances? but to no avail.