Created
August 31, 2009 22:16
-
-
Save afeinberg/178746 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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