Skip to content

Json serializer support for collections #29180

@steveharter

Description

@steveharter

This issue is to add built-in support for specific collections including:

System.Collections.Generic

  • IEnumerable<T>
  • ICollection<T>
  • IList<T>
  • IReadOnlyCollection<T>
  • IReadOnlyList<T>
  • ISet<T>
  • Stack<T>
  • Queue<T>
  • HashSet<T>
  • LinkedList<T>
  • SortedSet<T>
  • SortedDictionary<TKey, TValue>
  • KeyValuePair<TKey, TValue>

Future KeyedByCollection<TItem>, LinkedListNode<T>, SynchronizedCollection<T>, SynchronizedKeyCollection<K, T>, SynchronizedReadOnlyCollection<T>

Sytem.Collections

  • IEnumerable
  • ICollection
  • IList
  • IDictionary
  • Stack
  • Queue
  • Hashtable
  • ArrayList
  • SortedList

Future: BitArray

System.Collections.Immutable

  • IImmutableList<T>
  • IImmutableQueue<T>
  • IImmutableSet<T>
  • IImmutableStack<T>
  • IImmutableDictionary<TKey, TValue>
  • ImmutableArray<T>
  • ImmutableHashSet<T>
  • ImmutableList<T>
  • ImmutableQueue<T>
  • ImmutableSortedSet<T>
  • ImmutableStack<T>
  • ImmutableDictionary<TKey, TValue>
  • ImmutableSortedDictionary<TKey, TValue>

It should leverage the extensibility support for IEnumerable and register these interfaces.

Design notes:

  1. No new public APIs are needed.

2) The instance returned should only implement the specific interface. It should not be possible to cast to our implementation. This ensures we can change the type later if necessary and prevents other general misuses.
For example, the likely implementation for IEnumerable<T> is an internal class that implements IEnumerable<T> where the only public members are those used to implement IEnumerable<T>. The internal class then forwards each IEnumerable<T> member call to an instance of List<T> which is stored in a private field and thus not accessible publically and not castable to List<T> or other interfaces like IList<T>.

  1. We may want to also provide default implementations of some non-interfaces as well pending feedback (for example System.Collections.Immutable.ImmutableArray)

UPDATE
Also support System.Collections.Immutable and System.Collections.Generic (actual list TBD). These are not interfaces, but the same mechanism can be used to support them.

Metadata

Metadata

Assignees

Labels

area-System.Text.JsonblockingMarks issues that we want to fast track in order to unblock other important workdisabled-testThe test is disabled in source code against the issueenhancementProduct code improvement that does NOT require public API changes/additions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions