Custom deserialization with a hierarchy


I’m trying to implement a “Raw” deserializer for an object that contains a list of the same type. I’m manually creating my object and calling JsonSerializer.DeserializeFromString from my custom deserialization function. I can see the method being called once when doing:

var deserializedObject = JsonSerializer.DeserializeFromString<MyType>(@"{""SomeValue"":""abc"",""Children"":[{""SomeValue"":""def""}]}");

However my deserialization function is not called for the Children…is this the expected behavior? To prevent some kind of infinite loop? I’m fixing a bug using an old version (4.0.31) and I cannot update it; It is possible for my deserialization method to be called for the children?

// Register deserialization code
JsConfig<MyType>.RawDeserializeFn = CustomDeserialization


public static MyType CustomDeserialization(string s)
    var m = new MyType();
    var jo = JsonObject.Parse(s);
    m.SomeValue = jo["SomeValue"];
    m.Children = (List<MyType>)JsonSerializer.DeserializeFromString(jo["children"], typeof(List<MyType>));

    return m;


public class MyType
    public string SomeValue {get;set;}
    public List<MyType> Children {get;set;}

This is by design, once in a custom deserialize implementation it doesn’t trigger other custom implementations to avoid circular dependencies / StackOverflow exceptions. This behavior is hard coded and can’t be changed.

That’s what i thought. Thanks.