use of org.apache.avro.reflect.AvroName in project parquet-mr by apache.
the class AvroRecordConverter method getFieldsByName.
// this was taken from Avro's ReflectData
private static Map<String, Class<?>> getFieldsByName(Class<?> recordClass, boolean excludeJava) {
Map<String, Class<?>> fields = new LinkedHashMap<String, Class<?>>();
if (recordClass != null) {
Class<?> current = recordClass;
do {
if (excludeJava && current.getPackage() != null && current.getPackage().getName().startsWith("java.")) {
// skip java built-in classes
break;
}
for (Field field : current.getDeclaredFields()) {
if (field.isAnnotationPresent(AvroIgnore.class) || isTransientOrStatic(field)) {
continue;
}
AvroName altName = field.getAnnotation(AvroName.class);
Class<?> existing = fields.put(altName != null ? altName.value() : field.getName(), field.getType());
if (existing != null) {
throw new AvroTypeException(current + " contains two fields named: " + field.getName());
}
}
current = current.getSuperclass();
} while (current != null);
}
return fields;
}
Aggregations