My situation:
I've got a class from a library that has a bunch of fields I don't need and causes issues on deserialization, I only need one of the fields to serialize and deserialize. I've got it! JsonConverter will do the trick, right? So I want to serialize and deserialize the object using JsonConverter but my issue is I want to keep the "header" stuff Json.Net generates, like "$id" and "$type" because it's being serialized similar to other objects. I don't know where to find the $id of the current spot in serialization so I could use some help!
public override void WriteJson(JsonWriter writer, object v, JsonSerializer serializer)
{
MyObject myObject = (MyObject)v;
string myCoolString = myObject.myString;
MyObjectSerialized myObjectSerialized = new MyObjectSerialized()
{
myString = myCoolString
};
JObject jo = JObject.FromObject(myObjectSerialized);
jo.WriteTo(writer);
}
Output:
{
"myString":"test"
}
Expected output:
{
"$id":"34",
"$type":"MyObject, Assembly-CSharp",
"myString":"test"
}