Skip to content
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

Is it possible to make custom JSON converters public to support source generation? #549

Closed
1 task done
shenglol opened this issue Nov 3, 2023 · 1 comment · Fixed by #564
Closed
1 task done
Labels
enhancement New feature in an existing library pkg:pointer

Comments

@shenglol
Copy link

shenglol commented Nov 3, 2023

Describe the functionality that isn't covered by this suite.

I would like to utilize source generation in System.Text.Json for some POCOs that rely on types from this package, such as JsonPointer. However, it appears that the source generator consistently includes the custom JsonPointerJsonConverter, which is internal and is applied to the JsonPointer class, leading to a build failure.

The issue can be reproduced with the following code:

// Build error: 'JsonPointerJsonConverter' is inaccessible due to its protection level
public record ErrorResponse(string Code, string Message, JsonPointer? Target);

[JsonSerializable(typeof(ErrorResponse))]
public partial class ErrorResponseContext : JsonSerializerContext { }

Describe alternatives you've considered.

Would it be possible for you to consider changing the visibility of the custom JSON converters to public?

Is there any other information you'd like to share regarding this functionality?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@shenglol shenglol added the feature New JSON functionality to support in a new library label Nov 3, 2023
@gregsdennis gregsdennis added enhancement New feature in an existing library and removed feature New JSON functionality to support in a new library labels Nov 3, 2023
@gregsdennis
Copy link
Collaborator

gregsdennis commented Nov 17, 2023

Hey there. Sorry for not getting to this sooner.

I don't know a lot about the interaction between JSON source gen and the standard converters. My understanding was that they were different systems, but it seems the source gen uses converters if they're defined.

I don't see a problem with exposing them. I didn't originally because it wasn't necessary. (And I didn't want to write XML comments for more than I had to 😆.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature in an existing library pkg:pointer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants