Skip to content

Make converter types public #50192

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

agocke
Copy link

@agocke agocke commented May 21, 2025

In order to use source-generated JSON, the converter types need to be at least as accessible as the serialized types. This PR changes all public types which have converters to make those converters public.

@Copilot Copilot AI review requested due to automatic review settings May 21, 2025 22:01
@github-actions github-actions bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. labels May 21, 2025
Copy link

Thank you for your contribution @agocke! We will review the pull request and get back to you soon.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR makes JSON converter types public so they are as accessible as their associated serialized types, enabling source-generated JSON support.

  • Changed converter classes from internal to public
  • Added XML documentation comments for converters and their methods

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ResourceProviderData.cs Made ProviderDataConverter public and added docs
sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/Models/WritableSubResource.Serialization.cs Made WritableSubResourceConverter public and added docs
sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/Models/SubResource.Serialization.cs Made SubResourceConverter public and added docs
sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentityType.cs Made ManagedServiceIdentityTypeConverter public and added docs
sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs Made ManagedServiceIdentityConverter public and added docs
Comments suppressed due to low confidence (2)

sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ResourceProviderData.cs:58

  • Include XML tags for writer, providerData, and options parameters and a tag to ensure consistent and complete API documentation.
public override void Write(Utf8JsonWriter writer, ResourceProviderData providerData, JsonSerializerOptions options)

sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/ResourceProviderData.cs:53

  • Add unit tests to verify the serialization and deserialization behavior of this public converter to ensure JSON handling works as expected.
public partial class ProviderDataConverter : JsonConverter<ResourceProviderData>

@@ -47,7 +47,7 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri
if (Optional.IsDefined(Identity))
{
writer.WritePropertyName("identity"u8);
JsonSerializer.Serialize(writer, Identity);
JsonSerializer.Serialize(writer, Identity, AzureResourceManagerCosmosDBJsonContext.Default.ManagedServiceIdentity);
Copy link
Member

@m-nash m-nash May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should modify this to pass in a common instance of JsonSerializerOptions which uses https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/System.ClientModel/src/ModelReaderWriter/JsonModelConverter.cs and specifically calls the ctor that takes in AzureResourceManagerCostmosDBContext.Default

//internal helper somewhere
    internal readonly static JsonSerializerOptions s_options = new()
    {
        Converters =
        {
            new JsonModelConverter(ModelSerializationExtensions.WireOptions, AzureResourceManagerCosmosDBContext.Default)
        }
    };
//this line then becomes
JsonSerializer.Serialize(writer, Identity, s_options);

@agocke agocke force-pushed the public-jsonconverter branch from 1a6fcec to 25ce675 Compare May 22, 2025 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants