commit
79f9887625
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MediaBrowser.Common.Json.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a GUID object or value to/from JSON.
|
||||
/// </summary>
|
||||
public class GuidConverter : JsonConverter<Guid>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
=> new Guid(reader.GetString());
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using MediaBrowser.Common.Json.Converters;
|
||||
|
||||
namespace MediaBrowser.Common.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class for having compatible JSON throughout the codebase.
|
||||
/// </summary>
|
||||
public static class JsonDefaults
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the default <see cref="JsonSerializerOptions" /> options.
|
||||
/// </summary>
|
||||
/// <returns>The default <see cref="JsonSerializerOptions" /> options.</returns>
|
||||
public static JsonSerializerOptions GetOptions()
|
||||
{
|
||||
var options = new JsonSerializerOptions()
|
||||
{
|
||||
ReadCommentHandling = JsonCommentHandling.Disallow,
|
||||
WriteIndented = false
|
||||
};
|
||||
|
||||
options.Converters.Add(new GuidConverter());
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue