* Fix nullability of Children extension * Fix nullability of methods throughout the CMS * Fix return types of some methods that cannot return null * Revert nullable changes to result of ConvertSourceToIntermediate for property editors (whilst some property editors we know won't return null, it seems more consistent to adhere to the base class and interface nullability definition). * Updated new webhook events to align with new nullability definitions. * Reverted content editing service updates to align with base classes. * Applied collection nullability updates on content repository to interface. * Reverted value converter updates to match interface. * Applied further collection updates to interface. * Aligned media service interface with implementation for nullability. * Update from code review. --------- Co-authored-by: Ivo van der Bruggen <ivo@dutchbreeze.com> Co-authored-by: Ivo van der Bruggen <ivo@vdbruggensoftware.com> Co-authored-by: Andy Butland <abutland73@gmail.com>
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System.Text.Json;
|
|
|
|
namespace Umbraco.Cms.Infrastructure.Serialization;
|
|
|
|
/// <summary>
|
|
/// Converts a dictionary with a string key to or from JSON, using the <see cref="StringComparer.OrdinalIgnoreCase" /> comparer and interning the string key when reading.
|
|
/// </summary>
|
|
/// <typeparam name="TValue">The type of the dictionary value.</typeparam>
|
|
public sealed class JsonDictionaryStringInternIgnoreCaseConverter<TValue> : ReadOnlyJsonConverter<Dictionary<string, TValue>>
|
|
{
|
|
/// <inheritdoc />
|
|
public override Dictionary<string, TValue> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
if (reader.TokenType != JsonTokenType.StartObject)
|
|
{
|
|
throw new JsonException();
|
|
}
|
|
|
|
var dictionary = new Dictionary<string, TValue>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
while (reader.Read())
|
|
{
|
|
if (reader.TokenType == JsonTokenType.EndObject)
|
|
{
|
|
return dictionary;
|
|
}
|
|
|
|
// Get key
|
|
if (reader.TokenType != JsonTokenType.PropertyName)
|
|
{
|
|
throw new JsonException();
|
|
}
|
|
|
|
string propertyName = reader.GetString() ?? throw new JsonException();
|
|
|
|
// Get value
|
|
reader.Read();
|
|
TValue? value = JsonSerializer.Deserialize<TValue>(ref reader, options);
|
|
if (value is not null)
|
|
{
|
|
dictionary[string.Intern(propertyName)] = value;
|
|
}
|
|
}
|
|
|
|
throw new JsonException();
|
|
}
|
|
}
|