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
Add supported types article to System.Text.Json documentation #15807
All collections (any type that derives from IEnumerable)
are supported for serialization with JsonSerializer;
we simply call the .GetEnumerator()
method of the collection, and write the elements if they are supported. Deserialization is more complicated and is not supported for all collections.
This document gives a quick overview of which collections are supported.
For the purpose of serialization and deserialization in System.Text.Json, any
collection not in the BCL, (i.e. outside System.Collections[.[.\*]]), is considered
a custom collection. This includes user-defined types and ASP.NET defined types,
e.g. those in Microsoft.Extensions.Primitives.
A custom collection is supported for deserialization if it fulfils the following:
Activity
tdykstra commentedon Jan 21, 2020
JsonSerializercollection support in 3.1.xAll collections (any type that derives from
IEnumerable)are supported for serialization with
JsonSerializer;we simply call the
.GetEnumerator()method of the collection, and write the elements if they are supported. Deserialization is more complicated and is not supported for all collections.
This document gives a quick overview of which collections are supported.
Built-in types
System.CollectionsArrayListBitArrayHashtableQueueSortedListStack*DictionaryEntryICollectionIDictionaryIEnumerableIListSystem.Collections.GenericDictionary<string, TValue>HashSet<T>LinkedList<T>LinkedListNode<T>List<T>Queue<T>SortedDictionary<string, TValue>SortedList<string, TValue>SortedSet<T>Stack<T>*KeyValuePair<TKey, TValue>IAsyncEnumerable<T>ICollection<T>IDictionary<string, TValue>IEnumerable<T>IList<T>IReadOnlyCollection<T>IReadOnlyDictionary<string, TValue>IReadOnlyList<T>ISet<T>System.Collections.ImmutableImmutableArray<T>ImmutableDictionary<string, TValue>ImmutableHashSet<T>IImmutableList<T>ImmutableQueue<T>ImmutableSortedDictionary<string, TValue>ImmutableSortedSet<T>ImmutableStack<T>*IImmutableDictionary<string, TValue>IImmutableList<T>IImmutableQueue<T>IImmutableSet<T>IImmutableStack<T>*System.Collections.SpecializedBitVector32**HybridDictionaryIOrderedDictionaryListDictionaryStringCollectionStringDictionaryNameValueCollectionSystem.Collections.ConcurrentBlockingCollection<T>ConcurrentBag<T>ConcurrentDictionary<string, TValue>ConcurrentQueue<T>ConcurrentStack<T>*System.Collections.ObjectModelCollection<T>ObservableCollection<T>KeyedCollection<string, TValue>ReadOnlyCollection<T>ReadOnlyObservableCollection<T>ReadOnlyDictionary<string, TValue>Custom collections
For the purpose of serialization and deserialization in System.Text.Json, any
collection not in the BCL, (i.e. outside
System.Collections[.[.\*]]), is considereda custom collection. This includes user-defined types and ASP.NET defined types,
e.g. those in
Microsoft.Extensions.Primitives.
A custom collection is supported for deserialization if it fulfils the following:
IList,IList<T>,ICollection<T>,IDictionary,IDictionary<string, TValue>,Stack<T>*,Queue<T>,ConcurrentStack<T>*,ConcurrentQueue<T>,Stack*,and
QueueJsonSerializerAll custom collections (everything that derives from
IEnumerable)are supported for serialization, as long as their element types are supported.
There are known issues with some custom collections where we don't offer round-trippable support.
These include:
ExpandoObject: https://github.com/dotnet/corefx/issues/38007DynamicObject: https://github.com/dotnet/corefx/issues/41105DataTable: https://github.com/dotnet/corefx/issues/38712FormFile: https://github.com/dotnet/corefx/issues/41401IFormCollectionnullto value-type collections likeImmutableArray<T>: https://github.com/dotnet/corefx/issues/42399For more information, see the open issues in System.Text.Json.
*
Stack,Stack<T>,ImmutableStack<T>,IImmutableStack<T>,and
ConcurrentStack<T>instances; and instances of types that derive from them; are reversed on serialization. Thus, the serializer does not have round-trippable support
for these types. See https://github.com/dotnet/corefx/issues/41887.
** No exception is thrown when deserializing
BitVector32,but the
Dataproperty skipped because it is read-only (doesn't have a public setter).