diff --git a/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java b/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java index 7a73f698a..74e6b1ef6 100644 --- a/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java +++ b/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java @@ -331,7 +331,6 @@ private static class AnnotatedProperty { * * @param property must not be {@literal null}. */ - @SuppressWarnings("unchecked") public AnnotatedProperty(Property property) { Assert.notNull(property, "Property must not be null!"); @@ -340,10 +339,10 @@ public AnnotatedProperty(Property property) { Field field = ReflectionUtils.findField(property.getObjectType(), property.getName()); - this.type = firstNonEmpty( // - () -> Optional.ofNullable(property.getReadMethod()).map(ResolvableType::forMethodReturnType), // - () -> Optional.ofNullable(property.getWriteMethod()).map(it -> ResolvableType.forMethodParameter(it, 0)), // - () -> Optional.ofNullable(field).map(ResolvableType::forField)); + this.type = Optional.ofNullable(property.getReadMethod()).map(ResolvableType::forMethodReturnType) + .or(() -> Optional.ofNullable(property.getWriteMethod()).map(it -> ResolvableType.forMethodParameter(it, 0))) // + .or(() -> Optional.ofNullable(field).map(ResolvableType::forField)) + .orElseThrow(() -> new IllegalStateException("Could not resolve value!")); this.annotations = Stream.of(property.getReadMethod(), property.getWriteMethod(), field) // .filter(it -> it != null) // @@ -353,17 +352,6 @@ public AnnotatedProperty(Property property) { this.typeAnnotations = MergedAnnotations.from(this.type.resolve(Object.class)); } - @SuppressWarnings("unchecked") - private static T firstNonEmpty(Supplier>... suppliers) { - - Assert.notNull(suppliers, "Suppliers must not be null!"); - - return Stream.of(suppliers) // - .map(Supplier::get).flatMap(it -> it.map(Stream::of).orElseGet(Stream::empty)) // - .findFirst() // - .orElseThrow(() -> new IllegalStateException("Could not resolve value!")); - } - /** * Returns the name of the property. *