This project has moved and is read-only. For the latest updates, please go here.

To be able to serialize only ID field

Jul 27, 2014 at 10:50 AM
Edited Jul 27, 2014 at 10:52 AM
I want to modify JSON.NET so that when I am serializing Model from my API it sends only an array of IDs for composite Collection Object.

For e.g.

Class Employee {

ICollection<Address> Addresses {


Class Address {
int id;
string location;
string postcode;
Then when I send that back through webApi

Request.Createresponse(HttpStatusCode.OK, new Employee());

Then instead of:

{Addresses : [id:1, location: XX, postcode:XX],
[id:2, location: XX, postcode:XX]}
It just sends as:

{Addresss :[1,2]
I want this to be happening Application wide and I don't want to modify at the specific place.

How can I achieve through JSON.NET serializer?

Please note I don't want to use jsonignore attribute because then it will not serialize on when address is not used as composite field.

Please advise.