I ran into a problem with Json.Net.
My application is connected to a database and stores some data in it. Lets assume my application has three different classes: Entity, Group, Organisation
Short look into Entity class:
public class Entity
{
[JsonIgnore]
public int ID { get; private set; }
[JsonProperty]
public string UID { get; private set; }
[JsonProperty]
public Gender EntityGender { get; set; }
[JsonProperty]
public string Surname { get; set; }
[JsonProperty]
public string Forename { get; set; }
[JsonProperty]
public Group EntityGroup { get; set; }
[JsonProperty]
public Organisation EntityOrganisation { get; set; }
Organisation and Group also have an ID property.
When serializing an Entity I do not want to fully serialize EntityGroup and EntityOrganisation but only their IDs.
Some quick example how I would like it to look like:
(How it looks now)
{
"UID": "6c5204356b3a1a33",
"Surname": "Bar",
"Forename": "Foo",
"EntityGroup": {
"Name": "XGroup",
"GroupOrganisation": {
"Name": "FooOrg"
}
},
"EntityOrganisation": null,
"EntityStation": null
}
(How it should look like)
{
"UID": "6c5204356b3a1a33",
"Surname": "Bar",
"Forename": "Foo",
"EntityGroup": {
"ID": 1,
"GroupOrganisation": {
"ID": 1
}
},
"EntityOrganisation": null,
"EntityStation": null
}
Is it possible to setup a JsonParser that only serializes the ID property of Group and Organisation when serializing an Entity?