-
Notifications
You must be signed in to change notification settings - Fork 299
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
Internal class IntOrStringJsonConverter doesn't work with System.Text.Json Source Generator #1535
Comments
A little more context here would be that for some code paths, we log the json dump of the object that we're applying to the cluster so this doesn't affect the Client itself per se but would be nice for some of the observability things we do. So more generally, then I guess the ask is that either the appropriate converters + models are public, or that the associated source generator metadata can be made public enough for us to use them outside of the K8s Client itself |
I fixed this in, #1311 but it was closed. I would also like this PR to be completed, as I would like the performance benefits but don't plan on using full AOT. |
did you try Kubernetes.Aot? |
@peter-glotfelty could you please try example? @IvanJosipovic seesm too many warnings when introduce trimming to main sdk, not 100% if any bugs introduced by it |
Hi @tg123, thank you for following up, I tried switching to the Aot lib and that doesn't make the error go away. Here's my using System.Text.Json.Serialization;
using k8s.Models;
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(V1Pod))]
internal partial class SourceGenerationContext : JsonSerializerContext
{
} And the errors from dotnet publish -r win-x64
|
may i know why you have your own here is the one in aot, you do not have to create a new |
The scenario I'm running into is that I'm including a V1Pod in another class I have for auditing/logging. Since I want to serialize my wrapper into json, I need to create a SourceGenerationContext for my own type. However, the source generation for that fails because it doesn't have access to the internal member IntOrStringJsonConverter. Here's a simplified example with a little more context. // Example Class
public sealed class AdmissionControllerAuditLog
{
public bool Admitted { get; init; }
public string CreationSource { get; init; }
public V1Pod Target { get; init; }
}
[JsonSerializable(typeof(AdmissionControllerAuditLog))]
internal partial class SourceGenerationContext : JsonSerializerContext
{
} |
ah i see, this is by design at the moment. |
I also need the converters to be public as I'm generating classes for CRDs. Due to this, the provided SourceGenerationContext is not sufficient. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close not-planned |
@k8s-triage-robot: Closing this issue, marking it as "Not Planned". In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Describe the bug
I know the C# k8s client has been working to get compatible with source trimming. I tried to get Json serialization working, but get this error at compile time:
The 'JsonConverterAttribute' type 'k8s.Models.IntOrStringJsonConverter' specified on member 'k8s.Models.IntstrIntOrString' is not a converter type or does not contain an accessible parameterless constructor.
Kubernetes C# SDK Client Version
13.0.11
Dotnet Runtime Version
net6
To Reproduce
This snippet is enough for me to hit the warning along with adding
<IsTrimmable>true</IsTrimmable>
to my library projectExpected behavior
This shouldn't raise an error. InOrStringJsonConverter is internal so making it public would likely fix the issue, but I'll leave that up to you if that's the best fix or not.
The text was updated successfully, but these errors were encountered: