-
Notifications
You must be signed in to change notification settings - Fork 367
/
JsonFormatter.cs
34 lines (27 loc) · 1.15 KB
/
JsonFormatter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.DotNet.Interactive.Formatting;
public static class JsonFormatter
{
static JsonFormatter()
{
SerializerOptions = new JsonSerializerOptions
{
WriteIndented = false,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.AllowNamedFloatingPointLiterals,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
}
public static ITypeFormatter GetPreferredFormatterFor(Type type)
{
return Formatter.GetPreferredFormatterFor(type, MimeType);
}
public const string MimeType = "application/json";
internal static ITypeFormatter[] DefaultFormatters { get; } = DefaultJsonFormatterSet.DefaultFormatters;
public static JsonSerializerOptions SerializerOptions { get; }
}