How to implement a custom reference resolver

Feb 13, 2012 at 2:14 PM

I asked a question on StackOverflow that I can't get a good answer to:


I have the following JSON:

"id" : "2"
"categoryId" : "35"
"type" : "item"
"name" : "hamburger"
"id" : "35"
"type" : "category"
"name" : "drinks"

And I want to match it to this object:

public class Item 
[JsonProperty(PropertyName = "categoryId")]
public Category Category { get; set; }

Category is of type Entity which has a string Id property I can access. I want the "35" object created by the JSON Deserializer to be mapped to the Category property in the Item.

According to the documentation, I should use a IReferenceResolver. How would I implement this interface and hook it into the JSON.NET framework?


Any help would be appreciated.  Thanks!