Here's a sample that's close to what I'm trying to do:
void Main()
{
var settings = new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.None,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
};
var json = "{ \"$ref\": \"THIS IS DATA, NOT A JSON.NET REFERENCE\", \"other\": \"other\" }";
var deserialized = JsonConvert.DeserializeObject<MyType>(json, settings);
Console.WriteLine(deserialized.Ref);
}
[JsonObject(IsReference = false)]
public class MyType
{
[JsonProperty("$ref")]
public string Ref { get; set; }
[JsonProperty("other")]
public string Other { get; set; }
}
Basically, I need to process the "$ref" as a cross-document reference, or a reference to LATER in the current document. For more background, see the Swagger spec for Path Item Object.
Unfortunately, JSON.NET doesn't appear to allow this at all. I've tried a custom IReferenceResolver
implementation, but there isn't enough functionality available to resolve the references during deserialization. This is beacuse the references almost always resolve to an item that's later in the document and do not have a $id
property.