0

The JSON.NET deserializer recognizes a property named $id, and internally uses this property's value to identify the object. The server-side of my app populates these properties with unique values that are meaningful to the app. The POCOs on my app's client all have string ID properties.

How do I configure JSON.NET such that, upon deserialization, the $id values will be stored in the POCOs' string ID properties?

HappyNomad
  • 4,458
  • 4
  • 36
  • 55
  • Did you try [Deserializing $ref and $id](https://stackoverflow.com/q/2397511/3744182)? Or do you want to deserialize `"$id"` properties while still [preserving object references](https://www.newtonsoft.com/json/help/html/PreserveObjectReferences.htm)? – dbc Aug 21 '20 at 01:57
  • And also [Can not deserialize JSON containing $ref keys](https://stackoverflow.com/q/22299390/3744182). – dbc Aug 21 '20 at 02:08
  • @dbc I haven't tried `[JsonProperty(PropertyName = "$id")]` since those links say it won't work. I've configured JSON.NET to use `$id` for preserving object references, and need it to continue doing so. – HappyNomad Aug 21 '20 at 02:28
  • The answers to those question say that you can use `[JsonProperty(PropertyName = "$id")]` as long as you also set `MetadataPropertyHandling.Ignore`. But if you need to both preserve references and capture the `"$id"` into an object property, those answers might not work for you. Can you share a [mcve]? – dbc Aug 21 '20 at 03:11

0 Answers0