* @return The DatumReader for the given type
*/
@SuppressWarnings("unchecked")
public static <E> DatumReader<E> getDatumReaderForType(Class<E> type, Schema writerSchema) {
Schema readerSchema = getReaderSchema(type, writerSchema);
GenericData dataModel = getDataModelForType(type);
if (dataModel instanceof ReflectData) {
return new ReflectDatumReader<E>(writerSchema, readerSchema, (ReflectData)dataModel);
} else if (dataModel instanceof SpecificData) {
return new SpecificDatumReader<E>(writerSchema, readerSchema, (SpecificData)dataModel);
} else {