|
| 1 | +using GVFS.Common.Tracing; |
1 | 2 | using System; |
| 3 | +using System.Diagnostics.CodeAnalysis; |
2 | 4 | using System.Text.Json; |
| 5 | +using System.Text.Json.Serialization; |
| 6 | +using System.Text.Json.Serialization.Metadata; |
3 | 7 |
|
4 | 8 | namespace GVFS.Common |
5 | 9 | { |
6 | | - /// <summary> |
7 | | - /// Shared JsonSerializerOptions and helpers for the GVFS codebase. |
8 | | - /// PropertyNameCaseInsensitive preserves backward compatibility with |
9 | | - /// Newtonsoft.Json's default case-insensitive deserialization. |
10 | | - /// </summary> |
11 | 10 | public static class GVFSJsonOptions |
12 | 11 | { |
| 12 | + [UnconditionalSuppressMessage("AOT", "IL2026", |
| 13 | + Justification = "DefaultJsonTypeInfoResolver fallback handles all types at runtime.")] |
| 14 | + [UnconditionalSuppressMessage("AOT", "IL3050", |
| 15 | + Justification = "DefaultJsonTypeInfoResolver fallback handles all types at runtime.")] |
13 | 16 | public static readonly JsonSerializerOptions Default = new JsonSerializerOptions |
14 | 17 | { |
15 | 18 | PropertyNameCaseInsensitive = true, |
16 | | - Converters = { new VersionConverter(), new Tracing.EventMetadataConverter() }, |
| 19 | + Converters = { new VersionConverter(), new EventMetadataConverter() }, |
| 20 | + TypeInfoResolverChain = { GVFSJsonContext.Default, new DefaultJsonTypeInfoResolver() }, |
17 | 21 | }; |
18 | 22 |
|
19 | | - /// <summary> |
20 | | - /// Serialize using the compile-time type. Use when <typeparamref name="T"/> |
21 | | - /// is the concrete type (not a base class with derived properties). |
22 | | - /// </summary> |
| 23 | + [UnconditionalSuppressMessage("AOT", "IL2026", |
| 24 | + Justification = "TypeInfoResolverChain includes DefaultJsonTypeInfoResolver.")] |
| 25 | + [UnconditionalSuppressMessage("AOT", "IL3050", |
| 26 | + Justification = "TypeInfoResolverChain includes DefaultJsonTypeInfoResolver.")] |
23 | 27 | public static string Serialize<T>(T value) |
24 | 28 | { |
25 | 29 | return JsonSerializer.Serialize(value, Default); |
26 | 30 | } |
27 | 31 |
|
28 | | - /// <summary> |
29 | | - /// Serialize using the runtime type. Use when calling from a base-class |
30 | | - /// method where compile-time type would lose derived-class properties |
31 | | - /// (e.g., BaseResponse<T>.ToMessage()). |
32 | | - /// </summary> |
| 32 | + [UnconditionalSuppressMessage("AOT", "IL2026", |
| 33 | + Justification = "TypeInfoResolverChain includes DefaultJsonTypeInfoResolver.")] |
| 34 | + [UnconditionalSuppressMessage("AOT", "IL3050", |
| 35 | + Justification = "TypeInfoResolverChain includes DefaultJsonTypeInfoResolver.")] |
33 | 36 | public static string Serialize(object value, Type inputType) |
34 | 37 | { |
35 | 38 | return JsonSerializer.Serialize(value, inputType, Default); |
36 | 39 | } |
37 | 40 |
|
| 41 | + [UnconditionalSuppressMessage("AOT", "IL2026", |
| 42 | + Justification = "TypeInfoResolverChain includes DefaultJsonTypeInfoResolver.")] |
| 43 | + [UnconditionalSuppressMessage("AOT", "IL3050", |
| 44 | + Justification = "TypeInfoResolverChain includes DefaultJsonTypeInfoResolver.")] |
38 | 45 | public static T Deserialize<T>(string json) |
39 | 46 | { |
40 | 47 | return JsonSerializer.Deserialize<T>(json, Default); |
|
0 commit comments