I have an ASP MVC Web Api project that outputs json using json.net. I have for example the following models:
public class ModelA
{
public int Id {get;set;}
public string Name {get;set;}
[JsonIgnore]
public int TypeModelId {get;set;}
public virtual TypeModel TypeModel {get;set;}
}
public class TypeModel
{
[JsonIgnore]
public int Id {get;set;}
public string Name {get;set;}
[JsonIgnore]
public virtual IList<ModelA> ModelAs {get;set;}
}
When I serialize a ModelA the output will be something like this:
[
{
"Id": 1,
"Name": "test",
"TypeModel": {
"Name": "testtype1"
}
}
]
Is it possible using json.net to have an output like this..
[
{
"Id": 1,
"Name": "test",
"TypeModel": "testtype1"
}
]
..or do I have to copy the contents of ModelA to a new class which stores the TypeModel relation as string instead of reference? Maybe there are better solutions?