I have a backend-service that calls a REST-Api. The result of that API is then deserialized into my entity:
public class Item {
[JsonProperty("pkID")]
public int Id {get;set;}
}
JsonConvert.DeserializeObject<Item>(responseString);
This works fine. But I also want to return the result as a JSON-string so I can use it from the Frontend. When now Serializing my object of Type "Item" using JsonConvert.SerializeObject(item)
I want to return something like
{ Id: 1 }
Instead on serializing it also uses the JsonProperty and returns
{ pkID: 1 }
instead.
How can I tell the serializer to ignore the JsonProperty on serializing, but use it on deserializing?
I am NOT searching for a way whether the property should be serialized or not, but whether the propertyName should be used or the the name from the JsonProperty on serializing.