AvroUtils { public static <T> SchemaCoder<T> schemaCoder(TypeDescriptor<T> type) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) type.getRawType(); org.apache.avro.Schema avroSchema = new ReflectData(clazz.getClassLoader()).getSchema(clazz); Schema beamSchema = toBeamSchema(avroSchema); return SchemaCoder.of( beamSchema, type, getToRowFunction(clazz, avroSchema), getFromRowFunction(clazz)); } private  AvroUtils(); static Schema.Field toBeamField(org.apache.avro.Schema.Field field); static org.apache.avro.Schema.Field toAvroField(Schema.Field field, String namespace); static Schema toBeamSchema(org.apache.avro.Schema schema); static org.apache.avro.Schema toAvroSchema(
      Schema beamSchema, @Nullable String name, @Nullable String namespace); static org.apache.avro.Schema toAvroSchema(Schema beamSchema); static Row toBeamRowStrict(GenericRecord record, @Nullable Schema schema); static GenericRecord toGenericRecord(
      Row row, org.apache.avro.@Nullable Schema avroSchema); @SuppressWarnings("unchecked") static SerializableFunction<T, Row> getToRowFunction(
      Class<T> clazz, org.apache.avro.@Nullable Schema schema); @SuppressWarnings("unchecked") static SerializableFunction<Row, T> getFromRowFunction(Class<T> clazz); static @Nullable Schema getSchema(
      Class<T> clazz, org.apache.avro.@Nullable Schema schema); static SerializableFunction<GenericRecord, Row> getGenericRecordToRowFunction(
      @Nullable Schema schema); static SerializableFunction<Row, GenericRecord> getRowToGenericRecordFunction(
      org.apache.avro.@Nullable Schema avroSchema); static SchemaCoder<T> schemaCoder(TypeDescriptor<T> type); static SchemaCoder<T> schemaCoder(Class<T> clazz); static SchemaCoder<GenericRecord> schemaCoder(org.apache.avro.Schema schema); static SchemaCoder<T> schemaCoder(Class<T> clazz, org.apache.avro.Schema schema); static SchemaCoder<T> schemaCoder(AvroCoder<T> avroCoder); static List<FieldValueTypeInformation> getFieldTypes(Class<T> clazz, Schema schema); static List<FieldValueGetter> getGetters(Class<T> clazz, Schema schema); static SchemaUserTypeCreator getCreator(Class<T> clazz, Schema schema); @SuppressWarnings("unchecked") static @Nullable Object convertAvroFieldStrict(
      @Nullable Object value,
      @Nonnull org.apache.avro.Schema avroSchema,
      @Nonnull Schema.FieldType fieldType);  }
@Test public void testAvroSchemaCoders() { Pipeline pipeline = Pipeline.create(); org.apache.avro.Schema schema = org.apache.avro.Schema.createRecord( "TestSubRecord", "TestSubRecord doc", "org.apache.beam.sdk.schemas.utils", false, getAvroSubSchemaFields()); GenericRecord record = new GenericRecordBuilder(getAvroSubSchema("simple")) .set("bool", true) .set("int", 42) .build(); PCollection<GenericRecord> records = pipeline.apply(Create.of(record).withCoder(AvroCoder.of(schema))); assertFalse(records.hasSchema()); records.setCoder(AvroUtils.schemaCoder(schema)); assertTrue(records.hasSchema()); CoderProperties.coderSerializable(records.getCoder()); AvroGeneratedUser user = new AvroGeneratedUser("foo", 42, "green"); PCollection<AvroGeneratedUser> users = pipeline.apply(Create.of(user).withCoder(AvroCoder.of(AvroGeneratedUser.class))); assertFalse(users.hasSchema()); users.setCoder(AvroUtils.schemaCoder((AvroCoder<AvroGeneratedUser>) users.getCoder())); assertTrue(users.hasSchema()); CoderProperties.coderSerializable(users.getCoder()); }