2

Using Newtonsoft to (de)serialize Json, I want to refactor a propertyname without existing Json-markup to break.

F.e.:

{
  "old-very-specific-property": "value"
}

Should work just as fine as:

{
  "new-name": "value"
}

mapping to

public class Model {
  [JsonProperty, JsonRequired]
  public string NewName { get; set; } 
}

I want BOTH versions of Json above to map to the provided model, in order to maintain backwards compatibility.

Marco Jansen
  • 61
  • 1
  • 5
  • 1
    possible duplicate of http://stackoverflow.com/questions/19792274/alternate-property-name-while-deserializing/19885911#19885911 – nozzleman Nov 15 '16 at 13:11
  • [relevant](https://stackoverflow.com/questions/15915503/net-newtonsoft-json-deserialize-map-to-a-different-property-name) – user5226582 Nov 15 '16 at 13:11
  • 1
    See also [json deserialize from legacy property names](https://stackoverflow.com/questions/33155458/json-deserialize-from-legacy-property-names). – dbc Nov 15 '16 at 19:39
  • entirely forgot I asked the question. But I do like @TimRogers ' answer in dbc 's link best. Simple private set-only properties, making the backwards compatibility on object level instead of explicitly digging into converters and resolvers. – Marco Jansen Feb 08 '19 at 13:00

0 Answers0