MightyOrm / Mighty

A new, small, dynamic micro-ORM. Highly compatible with Massive, but with many essential new features.
BSD 3-Clause "New" or "Revised" License
101 stars 20 forks source link

System.Text.Json.JsonElement Support? #37

Closed FarzanHajian closed 3 years ago

FarzanHajian commented 3 years ago

Hi,

It seems there no native support for JsonElement objects yet (version 3.1.3).

I've tried to insert JsonElement instances directly and NameValueTypeEnumerator.GetEnumerator() raises an exception telling "Value-only collections not supported for action Insert". I've even tried converting my object to an ExpandoObject using ObjectExtensions.ToExpando() but that did not work as well.

Is there any workaround or any plan to support JsonElement for future?

Thanks,

mikebeaton commented 3 years ago

About a year or two ago now, I did think about adding support for Json objects in that enumerator which you have correctly identified - at the time it would have been for Newtonsoft.Json.

At that time, I decided against it because:

The existence of System.Text.Json slightly changes things - but it is still a dependency, and in fact worse, I think there'd be a poor case (still, for now) for supporting that but not supporting Newtonsoft.Json (or Json.NET? I seem to be out of date on that front!)

Regarding a use case, it's hard to implement something usefully without a good understanding of why it's needed, so I'd be interested to hear your reasons for needed to work with raw JSON (e.g., presumably, you're not working within the context of a .NET API project - or else, I would say, you should be allowing that to deserialize for you).

Regarding what you can do for now - I think you are going to have to manually deserialize to an object before passing to Mighty (i.e. using the features of System.Text.Json, not the features of Mighty). I am not sure if System.Text.Json supports deserializing to an arbitrary dynamic object (e.g. an Expando-based object). If it does, you can just pass that to Mighty. If it doesn't then you'd have to define the right target classes to deserialize to first (and then you might also prefer to use a strongly-typed instance of Mighty as well, though that'd still be up to you).

mikebeaton commented 3 years ago

@FarzanHajian - I'm closing this for now, as basically I am saying (as above) that I don't think Mighty is the right place to do this, but also that - with a little bit of extra code - you can already do it yourself.

Let me know if you disagree, or wish to discuss - or indeed try to persuade me! - further.

/Mike