Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization support for more implementing types in JsonSerializer #30646

Closed
layomia opened this issue Aug 21, 2019 · 2 comments · Fixed by dotnet/corefx#41482
Closed

Deserialization support for more implementing types in JsonSerializer #30646

layomia opened this issue Aug 21, 2019 · 2 comments · Fixed by dotnet/corefx#41482
Labels
area-System.Text.Json enhancement Product code improvement that does NOT require public API changes/additions json-functionality-doc Missing JSON specific functionality that needs documenting
Milestone

Comments

@layomia
Copy link
Contributor

layomia commented Aug 21, 2019

dotnet/corefx#39001 added support for types derived from BCL collections that are natively supported by the serializer, with the exception of read-only types, and types that do not implement any of:

  • IList
  • ICollection<T>
  • Stack<T>
  • Queue<T>
  • IDictionary
  • IDictionary<string, TValue>

Some examples are public class StackWrapper : Stack { } and StringValues. The serializer throws a NotSupportedException when a deserialization attempt is made for these types.

More investigation/design needs to be done, but these types can be supported by using reflection to probe for the right constructors to populate them if we determine to support them in the future.

@Tornhoof
Copy link
Contributor

The problem with Stack is simply, do you reverse the order during deserialization or not. I'm sure @JamesNK has input on that. I'm not sure that there is only one valid answer there so you might need to consider a setting for it.

@layomia
Copy link
Contributor Author

layomia commented Aug 22, 2019

The default behavior in the serializer for Stack<T>, Stack, ImmutableStack<T>, and types that derive from Stack<T> is:

Deserialization: if the payload is "[1,2,3]", we return a stack with 3 at the top.
Serialization: if stack's contents are [1, 2, 3] with 3 at the top, we return JSON payload [3,2,1].
This is what JSON.Net does.

I agree that a reversal setting should be considered if there's a demonstrated need. There'd be a performance cost for reversal opt-ins.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 5.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json enhancement Product code improvement that does NOT require public API changes/additions json-functionality-doc Missing JSON specific functionality that needs documenting
Projects
None yet
3 participants