Ok after looking into this more I believe what I wanted to do is better stated as I wanted to wrap my object inside multiple nested properties (JProperty). If there is a better/cleaner way of accomplishing this please let me know but this does the trick for now.
using a attribute on my base abstract class of
[JsonConverter(typeof(InputDataBaseConverter))]
and then creating a custom converter as follows:
public class InputDataBaseConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var operation = new JObject();
var details = new JObject();
var main = new JObject();
var type = value.GetType();
foreach (var prop in type.GetProperties())
{
if (!prop.CanRead) continue;
var propVal = prop.GetValue(value, null);
if (propVal != null)
main.Add(prop.Name, JToken.FromObject(propVal, serializer));
else if(serializer.NullValueHandling == NullValueHandling.Include)
main.Add(prop.Name, JToken.FromObject("null", serializer));
}
operation.AddFirst(new JProperty("Details", main));
details.AddFirst(new JProperty("operation",operation));
details.WriteTo(writer);
}
public override bool CanRead { get; } = false;
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new Exception("Not Needed");
}
public override bool CanConvert(Type objectType)
{
return objectType.IsAssignableFrom(typeof (InputDataBase));
}
}