Handlebars-Net/Handlebars.Net

untyped objects deserialised by System.Text.Json are unsupprted

Opened this issue · 0 comments

untyped objects with nested data deserialised by Newtonsoft can be used successfully with handlebars.net
consider:

var json = "{\"A\": {\"B\" : \"b\"}}";
object a = Newtonsoft.Json.JsonConvert.DeserializeObject(json)!;
string value = Handlebars.Create().Compile("{{A.B}}")(a);

value would be "b" (assuming I have no typos in the code.

However the same code won't work on an untyped object deserialised by System.Text.Json

object a = System.Text.Json.JsonSerializer.Deserialize<object>(json)!;
string value = Handlebars.Create().Compile("{{A.B}}")(a);

value will be "".

It would be great if the complex object deserialised by System.Text.Json could be used in handlebars templates, as per Newtonsoft.

Newtonsoft is not a part of the .NET standard library offering, and it would be good if Handlebars.NET worked well with the core libraries.

One key limitation that we have encountered is that untyped objects deserialised by Newtonsoft can't themselves be reliably serialised and deseriasied by the default .NET serialisation mechanism. This limits our ability to use Newtonsoft in our solution, and therefore we require native untyped object JSON support by handlebars.