Skip to content

Deserialization support for more implementing types in JsonSerializer #30646

Closed
dotnet/corefx
#41482

Description

@layomia

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.

Activity

  1. Tornhoof commented on Aug 21, 2019

    @Tornhoof
    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.

  2. layomia commented on Aug 22, 2019

    @layomia
    ContributorAuthor

    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.

  3. transferred this issue fromdotnet/corefxon Feb 1, 2020
  4. added this to the 5.0 milestone on Feb 1, 2020
  5. ghost locked as resolved and limited conversation to collaborators on Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.Jsonenhancementjson-functionality-doc

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions