diff --git a/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java b/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java index 45392975..484ebe25 100644 --- a/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java +++ b/src/main/java/org/springframework/hateoas/mediatype/PropertyUtils.java @@ -204,7 +204,7 @@ public class PropertyUtils { .filter(descriptor -> !FIELDS_TO_IGNORE.contains(descriptor.getName())) .filter(descriptor -> !descriptorToBeIgnoredByJackson(type, descriptor)) .filter(descriptor -> !toBeIgnoredByJackson(type, descriptor.getName())) - .filter(descriptor -> !readerIsNotToBeIgnoredByJackson(descriptor)); + .filter(descriptor -> !readerIsToBeIgnoredByJackson(descriptor)); } /** @@ -229,8 +229,11 @@ public class PropertyUtils { * @param descriptor * @return */ - private static boolean readerIsNotToBeIgnoredByJackson(PropertyDescriptor descriptor) { - return toBeIgnoredByJackson(MergedAnnotations.from(descriptor.getReadMethod())); + private static boolean readerIsToBeIgnoredByJackson(PropertyDescriptor descriptor) { + + Method reader = descriptor.getReadMethod(); + + return reader == null ? false : toBeIgnoredByJackson(MergedAnnotations.from(reader)); } /** diff --git a/src/test/java/org/springframework/hateoas/mediatype/PropertyUtilsTest.java b/src/test/java/org/springframework/hateoas/mediatype/PropertyUtilsTest.java index b12c3e93..5ff53a44 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/PropertyUtilsTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/PropertyUtilsTest.java @@ -156,6 +156,14 @@ class PropertyUtilsTest { }); } + @Test // #1121 + void considersPropertyWithoutReader() throws Exception { + + InputPayloadMetadata metadata = PropertyUtils.getExposedProperties(WithoutReaderMethod.class); + + assertThat(metadata.getPropertyMetadata("firstname")).isPresent(); + } + @Data @AllArgsConstructor @JsonIgnoreProperties({ "ignoreThisProperty" }) @@ -219,4 +227,13 @@ class PropertyUtilsTest { return employee.getContent(); } } + + static class WithoutReaderMethod { + + private String firstname; + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + } }