Skip to content

Internal class IntOrStringJsonConverter doesn't work with System.Text.Json Source Generator #1535

Closed as not planned
@peter-glotfelty

Description

@peter-glotfelty

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 project

using System.Text.Json.Serialization;
using k8s.Models;

namespace MyApp;

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(IntstrIntOrString))]
internal partial class MyAppJsonContext : JsonSerializerContext
{
}

Expected 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.

Metadata

Metadata

Assignees

Labels

lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions