Hi escamoteur,
Did you figure this out yet? Your C# object should be serializable for a start. You can also use the SerializeObject method of the JSON.NET library.
using Newtonsoft.Json;
Properties["doc"] =
JsonConvert.SerializeObject (entity, Formatting.Indented,
new JsonSerializerSettings {ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
});
Here, entity is my serializable C# object. I use JsonConvert along with some formatting and specify to ignore reference looping to prevent circular referencing.
On the deserializing end, this works nicely where TEntity is the class of your object.
var obj = doc.UserProperties["doc"];
var model = JsonConvert.DeserializeObject<TEntity>(obj.ToString());