private static Path<?> reifyPath(EntityPathResolver resolver, PropertyPath path, Optional<Path<?>> base) { Optional<Path<?>> map = base.filter(it -> it instanceof CollectionPathBase).map(CollectionPathBase.class::cast)// .map(CollectionPathBase::any)// .map(Path.class::cast)// .map(it -> reifyPath(resolver, path, Optional.of(it))); return map.orElseGet(() -> { Path<?> entityPath = base.orElseGet(() -> resolver.createPath(path.getOwningType().getType())); Field field = org.springframework.data.util.ReflectionUtils.findRequiredField(entityPath.getClass(), path.getSegment()); Object value = ReflectionUtils.getField(field, entityPath); PropertyPath next = path.next(); if (next != null) { return reifyPath(resolver, next, Optional.of((Path<?>) value)); } return (Path<?>) value; }); } }
/** * Returns the target {@link TypeDescriptor} for the given {@link PathInformation} by either inspecting the field or * property (the latter preferred) to pick up annotations potentially defined for formatting purposes. * * @param path must not be {@literal null}. * @return */ private static TypeDescriptor getTargetTypeDescriptor(PathInformation path) { PropertyDescriptor descriptor = path.getLeafPropertyDescriptor(); Class<?> owningType = path.getLeafParentType(); String leafProperty = path.getLeafProperty(); TypeDescriptor result = descriptor == null // ? TypeDescriptor .nested(org.springframework.data.util.ReflectionUtils.findRequiredField(owningType, leafProperty), 0) : TypeDescriptor .nested(new Property(owningType, descriptor.getReadMethod(), descriptor.getWriteMethod(), leafProperty), 0); if (result == null) { throw new IllegalStateException(String.format("Could not obtain TypeDesciptor for PathInformation %s!", path)); } return result; }