Skip to content

Instantly share code, notes, and snippets.

@afeinberg
Created August 31, 2009 22:16
Show Gist options
  • Save afeinberg/178746 to your computer and use it in GitHub Desktop.
Save afeinberg/178746 to your computer and use it in GitHub Desktop.
protected Class<? extends AvroSerializer> findSerializer(Class<?> type) {
if (type.isAnnotationPresent(AvroUseSerializer.class))
return type.getAnnotation(AvroUseSerializer.class).value();
return null;
}
// Later on
Class<? extends AvroSerializer> serializerClazz;
if ((serializerClazz = findSerializer(type)) != null) {
try {
@SuppressWarnings("unchecked")
AvroSerializer<Object> serializer = serializerClazz.newInstance();
DatumWriter<Object> writer = new GenericDatumWriter<Object>();
serializer.serialize(o, writer, entityStream);
} catch (Exception e) {
throw new IOException(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment