Describe the bug
I have the following simple assertion in my test:
For the following record:
public record AnyDto(
Long id,
@NotBlank
String name,
String description) { }
And even though I can see the object does have the property (set with a value), the test fails.
I have tracked this down, and it seems the "issue" is generated in the PropertyUtil class, in the propertyDescriptorsFor method:
|
return Introspector.getBeanInfo(fromObj.getClass(), stopClass).getPropertyDescriptors(); |
This is what Introspector.getBeanInfo(fromObj.getClass(), stopClass) retrieves for a Record class:

If I change the AnyDto to a regular class, the test passes, because the Introspector method above does contain PropertyDescriptors for the class:

Note: the Record does contain name as a MethodDescriptor, maybe we can rely on these for the Records?
This is a related Stackoverflow Question:
https://stackoverflow.com/questions/66982522/how-can-i-assert-hasproperty-with-a-java-record
Describe the bug
I have the following simple assertion in my test:
For the following record:
And even though I can see the object does have the property (set with a value), the test fails.
I have tracked this down, and it seems the "issue" is generated in the
PropertyUtilclass, in thepropertyDescriptorsFormethod:JavaHamcrest/hamcrest/src/main/java/org/hamcrest/beans/PropertyUtil.java
Line 49 in 5d76642
This is what
Introspector.getBeanInfo(fromObj.getClass(), stopClass)retrieves for a Record class:If I change the
AnyDtoto a regular class, the test passes, because the Introspector method above does containPropertyDescriptorsfor the class:Note: the Record does contain
nameas aMethodDescriptor, maybe we can rely on these for the Records?This is a related Stackoverflow Question:
https://stackoverflow.com/questions/66982522/how-can-i-assert-hasproperty-with-a-java-record