/** * Gets a converter for instances of the given class, capable of converting or wrapping them to Avro-compatible * instances. * * @param datumClass The class of the object that should be converted. * @return An instance that can convert to and from instances of the DatumT class to an Avro-compatible instance. * This instance can be reused. */ public <T> AvroConverter<T, ?> getConverter(Class<T> datumClass) { // If a converter exists, it is guaranteed to be correctly typed because of the register methods. // Try to get a private converter first. AvroConverter<T, ?> converter = getFromClassRegistry(mapConverter, datumClass); if (converter != null) { return converter; } // Fall-back on the shared converters. return getFromClassRegistry(mapSharedConverter, datumClass); }
match = getFromClassRegistry(map, datumClass.getSuperclass()); if (match != null) { return match; match = getFromClassRegistry(map, iClass); if (match != null) { return match;
/** * Creates a new instance of an {@link IndexedRecordConverter} that can be used to wrap or convert objects of the * specified class into {@link IndexedRecord}. * <p> * As a general rule, when the expected output {@link Schema} of the generated {@link IndexedRecord} is the same for * all incoming data, the factory should be cached and reused to optimize its performance. * * @param datumClass The class of the object that the {@link IndexedRecordConverter} knows how to wrap. * @return A new {@link IndexedRecordConverter} that can process instances of the datumClass, or null if none * exists. */ public <DatumT> IndexedRecordConverter<? super DatumT, ?> createIndexedRecordConverter(Class<DatumT> datumClass) { // This is guaranteed to be correctly typed if it exists, because of the register methods. @SuppressWarnings({ "rawtypes", "unchecked" }) Supplier<? extends IndexedRecordConverter<DatumT, ?>> converter = (Supplier) getFromClassRegistry( mapSharedIndexedRecordConverter, datumClass); if (converter == null && IndexedRecord.class.isAssignableFrom(datumClass)) { @SuppressWarnings("unchecked") IndexedRecordConverter<DatumT, ?> unconverted = (IndexedRecordConverter<DatumT, ?>) new UnconvertedIndexedRecordConverter<>(); return unconverted; } return converter == null ? null : converter.get(); }
SerializableFunction<? super DatumT, Schema> inferrer = getFromClassRegistry(mapSchemaInferrer, datum.getClass());