0

How to hide the EntityData object that are being mapped to JSON in post method of webapi

For Example: EntityData objects are below

public DateTimeOffset? CreatedAt { get; set; }
public bool Deleted { get; set; }
public string Id { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public byte[] Version { get; set; }

My Model looks like

public class area : EntityData
{
public string name {get;set;}
public string arealabel{get;set;}
}

so json object returns is

{
  "name": "sample string 1",
  "arealabel": "sample string 2",
  "id": "sample string 3",
  "__version": "QEBA",
  "__createdAt": "2015-12-16T13:18:22.752Z",
  "__updatedAt": "2015-12-16T13:18:22.752Z",
  "__deleted": true
}

But i need only name and arealabel to be shown in JSON object during post method
instead of writing request object separately. The json object should be like below

{
  "name": "sample string 1",
  "arealabel": "sample string 2"
}

Objective is to hide the entitydata object in post method

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Endeavour
  • 1
  • 1
  • 2
    if you're using newtonsoft, you can decarate your object with [JsonIgnore] attributes – Elph Dec 16 '15 at 13:37
  • we can't decorate the Entitydata object that is system properties with [JsonIgnore]. Is there any option to hide the system properties – Endeavour Jan 06 '16 at 05:17
  • Maybe this helps http://stackoverflow.com/questions/1791946/how-can-i-ignore-a-property-when-serializing-using-the-datacontractserializer – Elph Jan 07 '16 at 08:25

0 Answers0