Github user sihuazhou commented on a diff in the pull request:
https://github.com/apache/flink/pull/6151#discussion_r196366033
--- Diff:
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSerializer.java
---
@@ -105,41 +108,54 @@
/** The currently accessing thread, set and checked on debug level
only. */
private transient volatile Thread currentThread;
- //
------------------------------------------------------------------------
+ // ----------------------- instantiation methods
--------------------------
/**
* Creates a new AvroSerializer for the type indicated by the given
class.
- * This constructor is intended to be used with {@link SpecificRecord}
or reflection serializer.
- * For serializing {@link GenericData.Record} use {@link
AvroSerializer#AvroSerializer(Class, Schema)}
+ *
+ * <p>This constructor is expected to be used only with {@link
GenericRecord}.
+ * For {@link SpecificRecord} or reflection serializer use {@link
AvroSerializer#forNonGeneric(Class)}.
+ *
+ * @param schema the explicit schema to use for generic records.
*/
- public AvroSerializer(Class<T> type) {
- checkArgument(!isGenericRecord(type),
- "For GenericData.Record use constructor with explicit
schema.");
- this.type = checkNotNull(type);
- this.schemaString = null;
+ public static AvroSerializer<GenericRecord> forGeneric(Schema schema) {
+ return new AvroSerializer<>(GenericRecord.class, schema);
--- End diff --
Should we do checking for schema to make sure it not null here?
---