4

I was wondering how do I Serialize and De serialize a model using Json.net with a property changing names.

Example:

Model: {
 public int Id { get; set; }
 [JsonProperty("Id")]
 public String EventId { get; set; }
 public String Name { get; set; } 
}

The rest endpoint I hit to load the Data, passes me in the data as:

[{
 Id: 'A1B2C3D4-E1',
 Name: 'Event 1'
}]

I would like to pass out the information to my UI like:

[{
 Id: 1,
 Name: 'Event 1'
}]

I need to store the event's id in my database to check to see if it exists when repopulating the database from the rest endpoint. However I want to use my own Id field when working with the model. When Serializing to my UI, I need to see my Internal Id for foreign key relationships and not the string eventId (which will only be used for database AddOrUpdate)

Also note that the Id property is inherited from a base model, so just changing the jsonp name of Id isn't an option.

Jake Steele
  • 498
  • 3
  • 14
  • Is this answer any help http://stackoverflow.com/questions/8796618/how-can-i-change-property-names-when-serializing-with-json-net – FBTH Mar 18 '14 at 20:09
  • No unfortunately that would change it for both directions to be the same. – Jake Steele Mar 18 '14 at 20:11

0 Answers0