avro icon indicating copy to clipboard operation
avro copied to clipboard

Avro 3603 dotnet reflect make properties and method virtual in ClassCache, DotnetClass, DotnetProperty

Open KhrystynaPopadyuk opened this issue 3 years ago • 6 comments

What is the purpose of the change

This PR is my next attempt to brings flexibility and opportunity to override default logic for .NET reflect reader and writer. Please find more detail in https://issues.apache.org/jira/browse/AVRO-3603

As there is argument against using interfaces (https://github.com/apache/avro/pull/1940) so I made all properties, fields and methods in ClassCache, DotnetClass, DotnetProperty virtual. Also I update all private to protected to be able use and override in child implementation. This should allow similar flexibility as interface.

Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

Documentation

  • Does this pull request introduce a new feature? NO
  • If yes, how is the feature documented? N/A

KhrystynaPopadyuk avatar Dec 12 '22 02:12 KhrystynaPopadyuk

My biggest concern is calling the virtual functions from the constructors (see CodeQL complains). It must be addressed before merging.

Personally , I feel interfaces are a better solution here, but I understand the concerns about them as well.

zcsizmadia avatar Dec 14 '22 14:12 zcsizmadia

virtual functions from the constructors

I think those are not introduced with this PR.

martin-g avatar Dec 14 '22 15:12 martin-g

Hi @zcsizmadia , I remove "virtual" from methods that are called from constructor. Also, I made fields readonly as CodeQL suggested. Not sure why this changes are not reflected in scan result.

KhrystynaPopadyuk avatar Dec 16 '22 01:12 KhrystynaPopadyuk

Hi @martin-g , Current PR does not update serialization/deserialization or other core avro functionality. It is only about classes that parse/map dotnet type to avro schema. Also, event though this changes can be user to quickly handle errors and add desired functionality, this is not the main purpose.

Users/projects can have custom requirements that are not applicable for everyone and that should not be added to Apache.Avro. For example, at my project we use camel case naming convention for classes and properties (MyClass, MyProperty) for .NET, and there is requirement to use snake case naming for avro schemas across company (different languages) (my_class, my_property). Currently I use AvroField attribute to override property name. But this mean, each micro service should reefer to Apache.Avro and I should not forget to add that attribute to each property and not forget to update it when schema is changed (what happens often before release). After this PR I will be able to update property - field mapping to add implement custom requirements once.

KhrystynaPopadyuk avatar Dec 16 '22 01:12 KhrystynaPopadyuk

Can you please merge and release this PR?

vivere-dally avatar Jan 19 '23 10:01 vivere-dally

Hi @vivere-dally , This PR and https://github.com/apache/avro/pull/1940 are different approaches to resolve the same task. Only one should be merged.

I prefer https://github.com/apache/avro/pull/1940

KhrystynaPopadyuk avatar Jan 19 '23 10:01 KhrystynaPopadyuk