C# How to serialize/deserialize an Object to/from Dictionary<string,Object> to save/load it in Couchbase.lite

I’d like to share how to deserialize Dictionary to custom object using Newtonsoft.Json’s JObject class :

private MyCustomObject DeserializeUsingLinqToJson(string documentId)
{
    Document document = localDatabase.GetExistingDocument(documentId);
    Dictionary<string, object> properties = document.UserProperties;

    JObject obj = JObject.FromObject(properties);
    return obj.ToObject<MyCustomObject>();
}

Suppose it’s more effective than string-based JSON serialization described here.