Skip to content

Commit 19bd960

Browse files
AlexeyRagaanchitj
andauthored
Use schema from ISpecificRecord instead of reflecting a field (#1961)
* Use schema from ISpecificRecord instead of reflecting a field * Use writer type for serialisation * Added a line to CHANGELOG.md * Update CHANGELOG --------- Co-authored-by: Anchit Jain <[email protected]>
1 parent 5cd166f commit 19bd960

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Added SetSaslCredentials. This new method (on the Producer, Consumer, and AdminClient) allows modifying the stored
44
SASL PLAIN/SCRAM credentials that will be used for subsequent (new) connections to a broker (#1980).
55
- Fixed `OverflowException` thrown intermittently when using the `ListGroup` method (#2003).
6+
- Changed the way the `_SCHEMA` filed is accessed internally from reflecting the static field to accessing it from the instance ([AlexeyRaga](https://github.com/AlexeyRaga)).
67

78

89
# 2.0.2

src/Confluent.SchemaRegistry.Serdes.Avro/SpecificDeserializerImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public SpecificDeserializerImpl(ISchemaRegistryClient schemaRegistryClient)
5353

5454
if (typeof(ISpecificRecord).IsAssignableFrom(typeof(T)))
5555
{
56-
ReaderSchema = (global::Avro.Schema)typeof(T).GetField("_SCHEMA", BindingFlags.Public | BindingFlags.Static).GetValue(null);
56+
ReaderSchema = ((ISpecificRecord)Activator.CreateInstance<T>()).Schema;
5757
}
5858
else if (typeof(T).Equals(typeof(int)))
5959
{

src/Confluent.SchemaRegistry.Serdes.Avro/SpecificSerializerImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private static SerializerSchemaData ExtractSchemaData(Type writerType)
123123
SerializerSchemaData serializerSchemaData = new SerializerSchemaData();
124124
if (typeof(ISpecificRecord).IsAssignableFrom(writerType))
125125
{
126-
serializerSchemaData.WriterSchema = (global::Avro.Schema) writerType.GetField("_SCHEMA", BindingFlags.Public | BindingFlags.Static).GetValue(null);
126+
serializerSchemaData.WriterSchema = ((ISpecificRecord)Activator.CreateInstance(writerType)).Schema;
127127
}
128128
else if (writerType.Equals(typeof(int)))
129129
{

0 commit comments

Comments
 (0)