/** * Finds the {@link PropertyDescriptor} for the property with the given name on the given type. * * @param type must not be {@literal null}. * @param fieldname must not be {@literal null} or empty. * @return */ private static Optional<PropertyDescriptor> findPropertyDescriptor(Class<?> type, String fieldname) { PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(type, fieldname); if (descriptor != null) { return Optional.of(descriptor); } List<Class<?>> superTypes = new ArrayList<>(); superTypes.addAll(Arrays.asList(type.getInterfaces())); superTypes.add(type.getSuperclass()); return Streamable.of(type.getInterfaces()).stream()// .flatMap(it -> Optionals.toStream(findPropertyDescriptor(it, fieldname)))// .findFirst(); }
/** * Returns the {@link TypeInformation} for the given atomic field. Will inspect fields first and return the type of a * field if available. Otherwise it will fall back to a {@link PropertyDescriptor}. * * @see #getGenericType(PropertyDescriptor) * @param fieldname * @return */ @SuppressWarnings("null") private Optional<TypeInformation<?>> getPropertyInformation(String fieldname) { Class<?> rawType = getType(); Field field = ReflectionUtils.findField(rawType, fieldname); if (field != null) { return Optional.of(createInfo(field.getGenericType())); } return findPropertyDescriptor(rawType, fieldname).map(it -> createInfo(getGenericType(it))); }