Skip to content

Commit

Permalink
Change the order in which datum writer is selected
Browse files Browse the repository at this point in the history
Due to GenericRecord being checked before SpecificRecordBase,
GenericDatumWriter was used incorrectly for types that extend
SpecificRecordBase.

Resolves #3859
  • Loading branch information
abielewicz authored and fmbenhassine committed May 18, 2021
1 parent 4af4b05 commit f4e14dd
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 the original author or authors.
* Copyright 2019-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -155,14 +155,12 @@ private void initializeWriter() throws IOException {
}

private static <T> DatumWriter<T> datumWriterForClass(Class<T> clazz) {
if (GenericRecord.class.isAssignableFrom(clazz)) {
return new GenericDatumWriter<>();

}
if (SpecificRecordBase.class.isAssignableFrom(clazz)){
return new SpecificDatumWriter<>(clazz);
}

if (GenericRecord.class.isAssignableFrom(clazz)) {
return new GenericDatumWriter<>();
}
return new ReflectDatumWriter<>(clazz);
}

Expand Down

0 comments on commit f4e14dd

Please sign in to comment.