You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide option for the serializer to treat IEnumerables like objects with members #30855
Json Deserializers detect IEnumerable and expect the JSON at that level to therefore be a set (where this class represents a complex object containing both set metadata and set members). I can override that behaviour with Newtonsoft by adding the [JsonObject] attribute to the object and it does the job perfectly - and Newtonsoft's exception message gives a load of help which leads to this. I can't find a way to do the same for System.Text.Json. Also, really descriptive exception messages that guide the developer are one of my favourite things to create and see.
(Changing to an IReadOnlyCollection doesn't help, but ReadOnly IEnumerables could be a way to 'hint' that they're not meant to be deserialized into?)
I know there is a big library of junk for dealing with Amazon stuff. That is not the answer I'm looking for - it's likely to just add delay and potentially more questions. This is a working example of where this falls over.
In the immediate term, I'm likely to just create a customised collection to replace the array of dictionaries, but it would be cool if I could just convince the deserializer to fill the object.
changed the title [-]JsonSerializer.Deserialize<T> cannot serialize into custom IEnumerable[/-][+]JsonSerializer.Deserialize<T> cannot deserialize into custom IEnumerable[/+]on Sep 14, 2019
ReadOnly IEnumerables could be a way to 'hint' that they're not meant to be deserialized into
I don't think this is enough information for the serializer to change the normal behavior.
It seems that the way to move forward here is if there were an explicit way to tell the serializer to treat an IEnumerable like an object with properties, similar to Newtonsoft's [JsonObject] attribute. I'll rename this issue to reflect this.
changed the title [-]JsonSerializer.Deserialize<T> cannot deserialize into custom IEnumerable[/-][+]Provide option for the serializer to treat IEnumerables like objects with members[/+]on Jan 31, 2020
Activity
[-]JsonSerializer.Deserialize<T> cannot serialize into custom IEnumerable[/-][+]JsonSerializer.Deserialize<T> cannot deserialize into custom IEnumerable[/+]layomia commentedon Jan 31, 2020
I don't think this is enough information for the serializer to change the normal behavior.
It seems that the way to move forward here is if there were an explicit way to tell the serializer to treat an
IEnumerablelike an object with properties, similar to Newtonsoft's [JsonObject] attribute. I'll rename this issue to reflect this.[-]JsonSerializer.Deserialize<T> cannot deserialize into custom IEnumerable[/-][+]Provide option for the serializer to treat IEnumerables like objects with members[/+]layomia commentedon Feb 1, 2020
Closing as dup of #1808.