-
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Enable AOT-compatibility #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
956b5e6
5911a04
3446891
f1f6671
f1aff52
b9fa870
dc0a331
e4cc73f
133b799
bb7320f
858393a
0c00296
2b87054
a5aac93
b7bb2f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "test": { | ||
| "runner": "Microsoft.Testing.Platform" | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,15 @@ static JsonSerializer() | |
|
|
||
| private JsonSerializer() | ||
|
campersau marked this conversation as resolved.
|
||
| { | ||
| _options.TypeInfoResolver = JsonTypeInfoResolver.Combine( | ||
| DockerModelsJsonSerializerContext.Default, | ||
| DockerExtendedJsonSerializerContext.Default); | ||
| _options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; | ||
| _options.Converters.Add(new JsonEnumMemberConverter<RestartPolicyKind>()); | ||
| _options.Converters.Add(new JsonEnumMemberConverter<TaskState>()); | ||
| _options.Converters.Add(new JsonDateTimeConverter()); | ||
| _options.Converters.Add(new JsonNullableDateTimeConverter()); | ||
| _options.MakeReadOnly(); | ||
| } | ||
|
|
||
| public static JsonSerializer Instance { get; } | ||
|
|
@@ -38,26 +42,27 @@ public HttpContent GetHttpContent<T>(T value) | |
|
|
||
| public string Serialize<T>(T value) | ||
| { | ||
| return System.Text.Json.JsonSerializer.Serialize(value, _options); | ||
| return System.Text.Json.JsonSerializer.Serialize(value, JsonTypeInfoCache<T>.Value); | ||
| } | ||
|
|
||
| public byte[] SerializeToUtf8Bytes<T>(T value) | ||
| { | ||
| return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(value, _options); | ||
| return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(value, JsonTypeInfoCache<T>.Value); | ||
| } | ||
|
|
||
| public T Deserialize<T>(byte[] json) | ||
| { | ||
| return System.Text.Json.JsonSerializer.Deserialize<T>(json, _options)!; | ||
| return System.Text.Json.JsonSerializer.Deserialize(json, JsonTypeInfoCache<T>.Value)!; | ||
| } | ||
|
|
||
| public Task<T> DeserializeAsync<T>(HttpContent content, CancellationToken cancellationToken) | ||
| { | ||
| return content.ReadFromJsonAsync<T>(_options, cancellationToken)!; | ||
| return content.ReadFromJsonAsync(JsonTypeInfoCache<T>.Value, cancellationToken)!; | ||
| } | ||
|
|
||
| public async IAsyncEnumerable<T> DeserializeAsync<T>(Stream stream, [EnumeratorCancellation] CancellationToken cancellationToken) | ||
| { | ||
| var jsonTypeInfo = JsonTypeInfoCache<T>.Value; | ||
| var reader = PipeReader.Create(stream); | ||
|
|
||
| while (true) | ||
|
|
@@ -69,7 +74,7 @@ public async IAsyncEnumerable<T> DeserializeAsync<T>(Stream stream, [EnumeratorC | |
|
|
||
| while (!buffer.IsEmpty && TryParseJson(ref buffer, out var jsonDocument)) | ||
| { | ||
| yield return jsonDocument!.Deserialize<T>(_options)!; | ||
| yield return jsonDocument!.Deserialize(jsonTypeInfo)!; | ||
| } | ||
|
|
||
| if (result.IsCompleted) | ||
|
|
@@ -95,4 +100,59 @@ private static bool TryParseJson(ref ReadOnlySequence<byte> buffer, out JsonDocu | |
|
|
||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private static class JsonTypeInfoCache<T> | ||
| { | ||
| public static readonly JsonTypeInfo<T> Value = (JsonTypeInfo<T>)Instance._options.GetTypeInfo(typeof(T)); | ||
| } | ||
| } | ||
|
|
||
| // Additional source-generated metadata for collections and dictionaries used by operations. | ||
|
|
||
| [JsonSerializable(typeof(string))] | ||
| [JsonSerializable(typeof(IList<string>))] | ||
|
|
||
| // Filters | ||
| [JsonSerializable(typeof(IDictionary<string, IDictionary<string, bool>>))] | ||
| [JsonSerializable(typeof(IDictionary<string, string>))] | ||
|
|
||
| // ConfigOperations.ListConfigsAsync | ||
| [JsonSerializable(typeof(SwarmConfig[]))] | ||
|
|
||
| // ContainerOperations.ListContainersAsync | ||
| [JsonSerializable(typeof(ContainerListResponse[]))] | ||
| // ContainerOperations.InspectChangesAsync | ||
| [JsonSerializable(typeof(ContainerFileSystemChangeResponse[]))] | ||
|
|
||
| // ImageOperations.ListImagesAsync | ||
| [JsonSerializable(typeof(ImagesListResponse[]))] | ||
| // ImageOperations.GetImageHistoryAsync | ||
| [JsonSerializable(typeof(ImageHistoryResponse[]))] | ||
| // ImageOperations.DeleteImageAsync | ||
| [JsonSerializable(typeof(Dictionary<string, string>[]))] | ||
| // ImageOperations.SearchImagesAsync | ||
| [JsonSerializable(typeof(ImageSearchResponse[]))] | ||
| // ImageOperations.RegistryConfigHeaders | ||
| [JsonSerializable(typeof(Dictionary<string, AuthConfig>))] | ||
|
|
||
| // NetworkOperations.ListNetworksAsync | ||
| [JsonSerializable(typeof(NetworkResponse[]))] | ||
|
|
||
| // PluginOperations.ListPluginsAsync | ||
| [JsonSerializable(typeof(Plugin[]))] | ||
| // PluginOperations.GetPrivilegesAsync | ||
| [JsonSerializable(typeof(PluginPrivilege[]))] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have one more topic, but aside from the open discussions, the PR looks good. We can also address some of those in a follow-up PR if you prefer.
I belive the analyzer is a good idea 💡. I think these are missing too (or we change them to arrays too): // PluginOperations.InstallPluginAsync, UpgradePluginAsync
[JsonSerializable(typeof(IList<PluginPrivilege>))]
// PluginOperations.ConfigurePluginAsync
[JsonSerializable(typeof(IList<string>))]
// SecretsOperations.ListAsync
[JsonSerializable(typeof(IList<Secret>))]
// TasksOperations.ListAsync
[JsonSerializable(typeof(IList<TaskResponse>))] |
||
| // PluginOperations.InstallPluginAsync | ||
| [JsonSerializable(typeof(IList<PluginPrivilege>))] | ||
|
|
||
| // SecretOperations.ListAsync | ||
| [JsonSerializable(typeof(Secret[]))] | ||
|
|
||
| // SwarmOperations.ListServicesAsync | ||
| [JsonSerializable(typeof(SwarmService[]))] | ||
| // SwarmOperations.ListNodesAsync | ||
| [JsonSerializable(typeof(NodeListResponse[]))] | ||
|
|
||
| // TaskOperations.ListAsync | ||
| [JsonSerializable(typeof(TaskResponse[]))] | ||
| internal sealed partial class DockerExtendedJsonSerializerContext : JsonSerializerContext { } | ||
Uh oh!
There was an error while loading. Please reload this page.