feat: add non-generic Deserialize method with dynamic code requirements to KubernetesJson#1701
Conversation
…ts for JSON serialization
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: kimpenhaus The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @kimpenhaus! |
There was a problem hiding this comment.
Pull request overview
This PR adds a non-generic Deserialize(string json, Type returnType, JsonSerializerOptions jsonSerializerOptions = null) method to the KubernetesJson class. This provides an alternative to the existing generic Deserialize<TValue> methods when the target type is only known at runtime, enabling more flexible use of the Kubernetes client's JSON serialization infrastructure.
Key changes:
- Adds a new public non-generic Deserialize method that accepts a Type parameter
- Includes appropriate
RequiresDynamicCodeandRequiresUnreferencedCodeattributes for .NET 8.0+ to warn about AOT compatibility concerns - Imports
System.Diagnostics.CodeAnalysisnamespace for the new attributes
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…type support - implemented suggested improvements - added unit-test
…upport - added xml doc
…non-generic-method
# Conflicts: # tests/KubernetesClient.Tests/KubernetesJsonTests.cs
…ric-method' into feature/json-serializer-non-generic-method
|
what about i felt uncomfortable about the warning in sdk |
|
@tg123 thanks for the feedback - the warning mentioned by CoPilot is outdated - I've changed the code and there is no warning anymore. It's proper implemented now acording to the different sdk versions. One can go with the step to JsonElement for sure - but I think this feels more unnatural to general dotnet api. there used to be a generic and a non generic variant. |
this PR adds a non-generic Deserialise method to
KubernetesJson.csReason:
based on this discussion adding a non generic
Deserializemethod gives the opportunity to use the same json serialisation mechanism everywhere - when using KubernetesClient package.