diff --git a/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java b/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java index cc392efe..ac6cee4a 100644 --- a/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java +++ b/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java @@ -231,7 +231,7 @@ public class PropertyUtils { return type == null // ? Stream.empty() // : getPropertyDescriptors(type) // - .map(it -> new AnnotatedProperty(new Property(type, it.getReadMethod(), it.getWriteMethod()))) + .map(it -> new AnnotatedProperty(new Property(type, it.getReadMethod(), it.getWriteMethod(), it.getName()))) .map(it -> JSR_303_PRESENT ? new Jsr303AwarePropertyMetadata(it) : new DefaultPropertyMetadata(it)); } diff --git a/src/test/java/org/springframework/hateoas/mediatype/PropertyUtilsTest.java b/src/test/java/org/springframework/hateoas/mediatype/PropertyUtilsTest.java index 339e1c47..d618a38b 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/PropertyUtilsTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/PropertyUtilsTest.java @@ -164,6 +164,13 @@ class PropertyUtilsTest { assertThat(metadata.getPropertyMetadata("firstname")).isPresent(); } + @Test // #1402 + void detectesPropertiesWithRecordStyleAccessorsCorrectly() { + + assertThatNoException() + .isThrownBy(() -> PropertyUtils.getExposedProperties(TypeWithRecordStyleAccessors.class)); + } + @Data @AllArgsConstructor @JsonIgnoreProperties({ "ignoreThisProperty" }) @@ -236,4 +243,18 @@ class PropertyUtilsTest { this.firstname = firstname; } } + + // #1402 + static class TypeWithRecordStyleAccessors { + + private Boolean isActive; + + public Boolean isActive() { + return isActive; + } + + public void setActive(Boolean active) { + isActive = active; + } + } }