org.apache.avro.reflect.AvroIgnore Java Examples

The following examples show how to use org.apache.avro.reflect.AvroIgnore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvroUtils.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public List<FieldValueTypeInformation> get(Class<?> clazz) {
  Map<String, FieldValueTypeInformation> types = Maps.newHashMap();
  for (java.lang.reflect.Field f : ReflectUtils.getFields(clazz)) {
    if (!f.isAnnotationPresent(AvroIgnore.class)) {
      FieldValueTypeInformation typeInformation = FieldValueTypeInformation.forField(f);
      AvroName avroname = f.getAnnotation(AvroName.class);
      if (avroname != null) {
        typeInformation = typeInformation.withName(avroname.value());
      }
      types.put(typeInformation.getName(), typeInformation);
    }
  }
  return Lists.newArrayList(types.values());
}
 
Example #2
Source File: AvroRecordConverter.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
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.")) {
        break; // skip java built-in classes
      }
      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;
}