Scylin232 opened a new pull request, #3388:
URL: https://github.com/apache/avro/pull/3388

   ## Description
   
   Quote from AVRO-4137:
   
   At the moment, the C# library Avro matches Union types with Enum in the 
following way:
   
   ```csharp
   // SpecificDefaultWriter.cs - LN159 - protected override bool Matches(Schema 
sc, object obj)
   
   case Schema.Type.Enumeration:
      return obj.GetType().IsEnum && (sc as 
EnumSchema).Symbols.Contains(obj.ToString());
   ```
   
   This leads to the scenario where several Enums declared within one Union 
schema cannot have the same value names, because upon serialization, the Enum 
that is declared earlier will be chosen, not the one that was originally passed.
   
   It is further suggested to conduct a check on the type name and the schema 
itself:
   
   ```csharp
   case Schema.Type.Enumeration:
     return obj.GetType().IsEnum && (sc as 
EnumSchema).Symbols.Contains(obj.ToString()) && sc.Name == obj.GetType().Name;
   ```
   
   If you believe that this could lead to unforeseen problems (such as breaking 
backward compatibility), it is proposed to make the check optional, by default 
turned off. There may be other, more reliable methods to solve this issue, but 
the demonstrated one seemed the most optimal in my mind 😃 
   
   Thank you!
   
   ## What is the purpose of the change
   
   This pull request introduces SpecificWriter's Enum matching by name, fixing 
AVRO-4137
   
   ## Verifying this change
   
   This change is already covered by existing tests.
   
   ## Documentation
   
   - Does this pull request introduce a new feature? no
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@avro.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to