Assemblies
Namespaces
Types
ArrayConverter<TCollection, TElement>
BooleanConverter
ByteArrayConverter
ByteConverter
CharConverter
ConcurrentQueueOfTConverter<TCollection, TElement>
ConcurrentStackOfTConverter<TCollection, TElement>
DateTimeConverter
DateTimeOffsetConverter
DecimalConverter
DictionaryDefaultConverter<TDictionary, TKey, TValue>
DictionaryOfTKeyTValueConverter<TCollection, TKey, TValue>
DoubleConverter
EnumConverter<T>
EnumConverterFactory
EnumConverterOptions
FSharpListConverter<TList, TElement>
FSharpMapConverter<TMap, TKey, TValue>
FSharpOptionConverter<TOption, TElement>
FSharpSetConverter<TSet, TElement>
FSharpTypeConverterFactory
FSharpValueOptionConverter<TValueOption, TElement>
GuidConverter
IAsyncEnumerableOfTConverter<TAsyncEnumerable, TElement>
ICollectionOfTConverter<TCollection, TElement>
IDictionaryConverter<TDictionary>
IDictionaryOfTKeyTValueConverter<TDictionary, TKey, TValue>
IEnumerableConverter<TCollection>
IEnumerableConverterFactory
IEnumerableDefaultConverter<TCollection, TElement>
IEnumerableOfTConverter<TCollection, TElement>
IListConverter<TCollection>
IListOfTConverter<TCollection, TElement>
ImmutableDictionaryOfTKeyTValueConverter<TDictionary, TKey, TValue>
ImmutableDictionaryOfTKeyTValueConverterWithReflection<TCollection, TKey, TValue>
ImmutableEnumerableOfTConverter<TCollection, TElement>
ImmutableEnumerableOfTConverterWithReflection<TCollection, TElement>
Int16Converter
Int32Converter
Int64Converter
IReadOnlyDictionaryOfTKeyTValueConverter<TDictionary, TKey, TValue>
ISetOfTConverter<TCollection, TElement>
JsonArrayConverter
JsonDocumentConverter
JsonElementConverter
JsonMetadataServicesConverter<T>
JsonNodeConverter
JsonNodeConverterFactory
JsonObjectConverter
JsonValueConverter
KeyValuePairConverter<TKey, TValue>
LargeJsonObjectExtensionDataSerializationState
LargeObjectWithParameterizedConstructorConverter<T>
LargeObjectWithParameterizedConstructorConverterWithReflection<T>
ListOfTConverter<TCollection, TElement>
NullableConverter<T>
NullableConverterFactory
ObjectConverter
ObjectConverterFactory
ObjectDefaultConverter<T>
ObjectWithParameterizedConstructorConverter<T>
QueueOfTConverter<TCollection, TElement>
SByteConverter
SingleConverter
SmallObjectWithParameterizedConstructorConverter<T, TArg0, TArg1, TArg2, TArg3>
StackOfTConverter<TCollection, TElement>
StackOrQueueConverter<TCollection>
StackOrQueueConverterWithReflection<TCollection>
StringConverter
TimeSpanConverter
UInt16Converter
UInt32Converter
UInt64Converter
UnsupportedTypeConverter<T>
UnsupportedTypeConverterFactory
UriConverter
VersionConverter
LargeJsonObjectExtensionDataSerializationState
Implements a mitigation for deserializing large JsonObject extension data properties.
Extension data properties use replace semantics when duplicate keys are encountered,
which is an O(n) operation for JsonObject resulting in O(n^2) total deserialization time.
This class mitigates the performance issue by storing the deserialized properties in a
temporary dictionary (which has O(1) updates) and copies them to the destination object
at the end of deserialization.
using System .
Collections .
Generic ;
using System .
Text .
Json .
Nodes ;
namespace System .
Text .
Json .
Serialization .
Converters
{
internal sealed class LargeJsonObjectExtensionDataSerializationState
{
public const int LargeObjectThreshold =
25 ;
private readonly Dictionary <
string ,
JsonNode >
_tempDictionary ;
public JsonObject Destination { get; }
public LargeJsonObjectExtensionDataSerializationState (
JsonObject destination )
{
StringComparer comparer = (
destination .
Options ?.
PropertyNameCaseInsensitive ??
false ) ?
StringComparer .
OrdinalIgnoreCase :
StringComparer .
Ordinal ;
Destination =
destination ;
_tempDictionary =
new Dictionary <
string ,
JsonNode >(
comparer );
}
public void AddProperty (
string key ,
JsonNode value )
{
_tempDictionary [
key ] =
value ;
}
public void Complete ()
{
foreach (
KeyValuePair <
string ,
JsonNode >
item in _tempDictionary ) {
Destination [
item .
Key ] =
item .
Value ;
}
}
}
}