-
-
Notifications
You must be signed in to change notification settings - Fork 14
Enable IsAotCompatible #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
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() | ||
|
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 think the following is slightly better, although the improvements compared to network I/O are probably negligible. WDYT? Subject: [PATCH] f
---
Index: src/Docker.DotNet/JsonSerializer.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Docker.DotNet/JsonSerializer.cs b/src/Docker.DotNet/JsonSerializer.cs
--- a/src/Docker.DotNet/JsonSerializer.cs (revision e4cc73fdd8371f3dd6110684f6e7a705b55941c4)
+++ b/src/Docker.DotNet/JsonSerializer.cs (date 1776437559579)
@@ -42,26 +42,27 @@
public string Serialize<T>(T value)
{
- return System.Text.Json.JsonSerializer.Serialize(value, (JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T)));
+ return System.Text.Json.JsonSerializer.Serialize(value, TypeInfoCache<T>.Value);
}
public byte[] SerializeToUtf8Bytes<T>(T value)
{
- return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(value, (JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T)));
+ return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(value, TypeInfoCache<T>.Value);
}
public T Deserialize<T>(byte[] json)
{
- return System.Text.Json.JsonSerializer.Deserialize(json, (JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T)))!;
+ return System.Text.Json.JsonSerializer.Deserialize(json, TypeInfoCache<T>.Value)!;
}
public Task<T> DeserializeAsync<T>(HttpContent content, CancellationToken cancellationToken)
{
- return content.ReadFromJsonAsync((JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T)), cancellationToken)!;
+ return content.ReadFromJsonAsync(TypeInfoCache<T>.Value, cancellationToken)!;
}
public async IAsyncEnumerable<T> DeserializeAsync<T>(Stream stream, [EnumeratorCancellation] CancellationToken cancellationToken)
{
+ var typeInfo = TypeInfoCache<T>.Value;
var reader = PipeReader.Create(stream);
while (true)
@@ -73,7 +74,7 @@
while (!buffer.IsEmpty && TryParseJson(ref buffer, out var jsonDocument))
{
- yield return jsonDocument!.Deserialize((JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T)))!;
+ yield return jsonDocument!.Deserialize(typeInfo)!;
}
if (result.IsCompleted)
@@ -99,6 +100,11 @@
return false;
}
+
+ private static class TypeInfoCache<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.
|
||
| { | ||
| _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,22 +42,22 @@ 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, (JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T))); | ||
| } | ||
|
|
||
| public byte[] SerializeToUtf8Bytes<T>(T value) | ||
| { | ||
| return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(value, _options); | ||
| return System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(value, (JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T))); | ||
| } | ||
|
|
||
| public T Deserialize<T>(byte[] json) | ||
| { | ||
| return System.Text.Json.JsonSerializer.Deserialize<T>(json, _options)!; | ||
| return System.Text.Json.JsonSerializer.Deserialize(json, (JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T)))!; | ||
| } | ||
|
|
||
| public Task<T> DeserializeAsync<T>(HttpContent content, CancellationToken cancellationToken) | ||
| { | ||
| return content.ReadFromJsonAsync<T>(_options, cancellationToken)!; | ||
| return content.ReadFromJsonAsync((JsonTypeInfo<T>)_options.GetTypeInfo(typeof(T)), cancellationToken)!; | ||
| } | ||
|
|
||
| public async IAsyncEnumerable<T> DeserializeAsync<T>(Stream stream, [EnumeratorCancellation] CancellationToken cancellationToken) | ||
|
|
@@ -69,7 +73,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<T>)_options.GetTypeInfo(typeof(T)))!; | ||
| } | ||
|
|
||
| if (result.IsCompleted) | ||
|
|
@@ -95,4 +99,40 @@ private static bool TryParseJson(ref ReadOnlySequence<byte> buffer, out JsonDocu | |
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Additional source-generated metadata for collections and dictionaries used by operations. | ||
|
|
||
| // Filters | ||
| [JsonSerializable(typeof(IDictionary<string, IDictionary<string, bool>>))] | ||
|
|
||
| // 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[]))] | ||
|
|
||
| // 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>))] |
||
|
|
||
| // SwarmOperations.ListServicesAsync | ||
| [JsonSerializable(typeof(SwarmService[]))] | ||
| // SwarmOperations.ListNodesAsync | ||
| [JsonSerializable(typeof(NodeListResponse[]))] | ||
| internal sealed partial class DockerExtendedJsonSerializerContext : JsonSerializerContext { } | ||
Uh oh!
There was an error while loading. Please reload this page.