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
Deserialization support for more implementing types in JsonSerializer #30646
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.
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.
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.
Activity
Tornhoof commentedon Aug 21, 2019
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 commentedon Aug 22, 2019
The default behavior in the serializer for
Stack<T>,Stack,ImmutableStack<T>, and types that derive fromStack<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.