Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 9, 2025

Extends JSON property naming control by introducing a PropertyNamingSource enum that replaces the boolean UseProtobufJsonNames flag, adding support for using original .proto field names.

Changes

  • New PropertyNamingSource enum with three options:

    • Default - Uses PropertyNamingPolicy (existing default)
    • ProtobufJsonName - Uses protobuf JsonName (camelCase or custom json_name)
    • ProtobufFieldName - Uses original .proto field name (e.g., double_property)
  • Backward compatibility: UseProtobufJsonNames marked obsolete, maps to new enum

  • Updated ProtobufConverter: Refactored GetConvertNameFunc to use switch on enum, accessing descriptor.Name for field names

Usage

var options = new JsonSerializerOptions();
options.AddProtobufSupport(opts => 
{
    opts.PropertyNamingSource = PropertyNamingSource.ProtobufFieldName;
});

// For a field defined as "double_property" in .proto:
var json = JsonSerializer.Serialize(msg, options);
// Result: {"double_property": 2.5} instead of {"doubleProperty": 2.5}

Works correctly with custom json_name in .proto files - ProtobufFieldName uses the original field name regardless of json_name overrides.

Original prompt

This section details on the original issue you should resolve

<issue_title>Use names defined in .proto files as JSON property names to override PropertyNamingPolicy</issue_title>
<issue_description>## Feature description

Currently, the UseProtobufJsonNames flag allows overriding the PropertyNamingPolicy from System.Text.Json by using the protobuf JsonName.

We’d like to extend this functionality to support using the original field names defined directly in .proto files instead of the computed JsonName values.</issue_description>

<agent_instructions>try to implement this. add new enum that will obsolete the existing flag </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 9, 2025 22:59
Co-authored-by: Havret <9103861+Havret@users.noreply.github.com>
Co-authored-by: Havret <9103861+Havret@users.noreply.github.com>
Co-authored-by: Havret <9103861+Havret@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for JSON property names from .proto files Add PropertyNamingSource enum to support proto field names Nov 9, 2025
Copilot AI requested a review from Havret November 9, 2025 23:06
Copy link
Owner

@Havret Havret left a comment

Choose a reason for hiding this comment

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

LGTM ❤️

@Havret Havret marked this pull request as ready for review November 9, 2025 23:12
@Havret Havret merged commit 3bc8b8a into main Nov 9, 2025
2 checks passed
@Havret Havret deleted the copilot/extend-json-naming-policy branch November 9, 2025 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use names defined in .proto files as JSON property names to override PropertyNamingPolicy

2 participants