Last active
December 14, 2015 11:08
-
-
Save gongdo/233b66d8d015b3c064f7 to your computer and use it in GitHub Desktop.
How to set different json property name between serialization and deserialization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Document | |
{ | |
// actual property | |
[JsonIgnore] | |
public string Value { get; set; } | |
// performs serialization only. | |
[JsonProperty("PresentationValueName")] | |
private string ValueGetter { get { return Value; } } | |
// performs deserialization only. | |
[JsonProperty("PersistenceValueName")] | |
private string ValueSetter { set { Value = value; } } | |
} | |
/* JsonConvert.SerializeObject(new Document { Value = "gongdo" }); | |
{ "PresentationValueName":"gongdo" } | |
*/ | |
/* JsonConvert.DeserializeObject<Document>("{ \"PersistenceValueName\":\"gongdo\" }"); | |
// Document.Value: "gongdo" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment