Suppose I have these classes:
public class Bar
{
public Foo MyFoo { get; set; }
}
public class Foo
{
public string[] Stuff { get; set; }
}
And I have this JSON structure:
{
"MyFoo":
{
"Stuff":"those,are,my,stuff"
}
}
And I have a code path where a JObject
is being converted to Bar
using code like below:
myJObject.ToObject(typeof(Bar))
Now what I need to do is to supply the ToObject
with a custom serializer to convert the string property Stuff
into an array of string (using string.Split(...).ToArray()
)
I was asked not to add attributes on the client class 'Bar' so after looking around it seemed like a ContractResolver
is in order but the issue is that the resolver only lets me handle direct properties of the root Type, that is Bar
in my example, and I can't register a JsonConverter
on a nested property.
So my question to you guys is, is this even achievable using Json.net?
- Note that I need to do this not only for the
Bar
class but to an unlimited amount of classes with unknown structure so I can't hard-code a solution that will work for one type of class.