From 6836552e2573b833f3375b1a781625897688d1c2 Mon Sep 17 00:00:00 2001 From: Tony Liao Date: Tue, 25 Aug 2026 10:48:17 -0700 Subject: [PATCH] Allow later enum aliases to overwrite in C# custom JSON enum mapping. When constructing the custom JSON enum name map in C# JsonParser, remove the ContainsKey check so that subsequent aliased enum values overwrite earlier ones, aligning with the "last match wins" semantics used across C++, Java, PHP, and Python. PiperOrigin-RevId: 970656172 --- csharp/src/Google.Protobuf/JsonParser.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/csharp/src/Google.Protobuf/JsonParser.cs b/csharp/src/Google.Protobuf/JsonParser.cs index 6db3b8e072..ef9de22820 100644 --- a/csharp/src/Google.Protobuf/JsonParser.cs +++ b/csharp/src/Google.Protobuf/JsonParser.cs @@ -774,8 +774,7 @@ namespace Google.Protobuf { var jsonOptions = value.GetOptions()?.GetExtension( Pb.Enumvalue.JsonEnumvalueOptionsExtensions.Json); - if (jsonOptions != null && jsonOptions.HasString && - !map.ContainsKey(jsonOptions.String)) + if (jsonOptions != null && jsonOptions.HasString) { map[jsonOptions.String] = value; }