Skip to content

Commit

Permalink
#1121 - Shortcut ignored property lookups to prevent NullPointerExcep…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
odrotbohm committed Nov 18, 2019
1 parent fc42597 commit aa9e449
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Expand Up @@ -204,7 +204,7 @@ private static Stream<PropertyDescriptor> getPropertyDescriptors(Class<?> type)
.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));
}

/**
Expand All @@ -229,8 +229,11 @@ private static boolean descriptorToBeIgnoredByJackson(Class<?> clazz, PropertyDe
* @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));
}

/**
Expand Down
Expand Up @@ -156,6 +156,14 @@ void considersJsr303Annotations() {
});
}

@Test // #1121
void considersPropertyWithoutReader() throws Exception {

InputPayloadMetadata metadata = PropertyUtils.getExposedProperties(WithoutReaderMethod.class);

assertThat(metadata.getPropertyMetadata("firstname")).isPresent();
}

@Data
@AllArgsConstructor
@JsonIgnoreProperties({ "ignoreThisProperty" })
Expand Down Expand Up @@ -219,4 +227,13 @@ public Employee newEmployee(@RequestBody EntityModel<Employee> employee) {
return employee.getContent();
}
}

static class WithoutReaderMethod {

private String firstname;

public void setFirstname(String firstname) {
this.firstname = firstname;
}
}
}

0 comments on commit aa9e449

Please sign in to comment.