private ClassAccessorData(Class<?> c) { clazz = c; for(Field f : getFields(c, false)) { if (f.isAnnotationPresent(AvroIgnore.class)) { continue; } FieldAccessor accessor = ReflectionUtil.getFieldAccess().getAccessor(f); AvroName avroname = f.getAnnotation(AvroName.class); byName.put( (avroname != null ? avroname.value() : f.getName()) , accessor); } }
private static class FieldWithAvroName { @AvroName("name") @SuppressWarnings("unused") private int someField; }
private static class SubclassHidingParent extends UnorderedMapClass { @SuppressWarnings("unused") @AvroName("mapField2") // AvroName is not enough private int mapField; }
private ClassAccessorData(Class<?> c) { clazz = c; for(Field f : getFields(c, false)) { if (f.isAnnotationPresent(AvroIgnore.class)) { continue; } FieldAccessor accessor = ReflectionUtil.getFieldAccess().getAccessor(f); AvroName avroname = f.getAnnotation(AvroName.class); byName.put( (avroname != null ? avroname.value() : f.getName()) , accessor); } }
? annotatedName.value() : field.getName(); Schema.Field recordField
? annotatedName.value() : field.getName(); Schema.Field recordField
/** * Extract a field from a class. We need to look at the declared fields so that we can see * private fields. We may need to walk up to the parent to get classes from the parent. */ private static Field getField(Class<?> originalClazz, String name) { Class<?> clazz = originalClazz; while (clazz != null) { for (Field field : clazz.getDeclaredFields()) { AvroName avroName = field.getAnnotation(AvroName.class); if (avroName != null && name.equals(avroName.value())) { return field; } else if (avroName == null && name.equals(field.getName())) { return field; } } clazz = clazz.getSuperclass(); } throw new IllegalArgumentException("Unable to get field " + name + " from " + originalClazz); } }
private ClassAccessorData(Class<?> c) { clazz = c; for(Field f : getFields(c, false)) { if (f.isAnnotationPresent(AvroIgnore.class)) { continue; } FieldAccessor accessor = ReflectionUtil.getFieldAccess().getAccessor(f); AvroName avroname = f.getAnnotation(AvroName.class); byName.put( (avroname != null ? avroname.value() : f.getName()) , accessor); } }
private ClassAccessorData(Class<?> c) { clazz = c; for(Field f : getFields(c, false)) { if (f.isAnnotationPresent(AvroIgnore.class)) { continue; } FieldAccessor accessor = ReflectionUtil.getFieldAccess().getAccessor(f); AvroName avroname = f.getAnnotation(AvroName.class); byName.put( (avroname != null ? avroname.value() : f.getName()) , accessor); } }
protected PropertyName _findName(Annotated a) { AvroName ann = _findAnnotation(a, AvroName.class); return (ann == null) ? null : PropertyName.construct(ann.value()); }
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; }
? annotatedName.value() : field.getName(); Schema.Field recordField
? annotatedName.value() : field.getName(); Schema.Field recordField