Ihor Mochurad (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ccb2fc...
) *created* an issue
Hibernate Validator (
https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiNmI3MTAxMzhmN...
) / Bug (
https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiNmI3MTAx...
) HV-1794 (
https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiNmI3MTAx...
) Optional containing a list of items is not being validated (
https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiNmI3MTAx...
)
Issue Type: Bug Affects Versions: 6.0.18.Final Assignee: Unassigned Components: engine
Created: 22/Jul/2020 15:46 PM Priority: Major Reporter: Ihor Mochurad (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ccb2fc...
)
As a user of Hibernate Validator, I would expect that a field like
`private Optional<List<ConsumerGroupDTO>> consumerGroups;`
where `ConsumerGroupDTO` is the following pojo:
@Data
@SuperBuilder
@NoArgsConstructor
public class ConsumerGroupDTO extends ConsumerDTO {
private @NotEmpty String consumerGroupId;
private boolean simpleConsumerGroup;
}
gets properly validated and constraint violation exception will be thrown in case
`consumerGroupId` value will be set either to null or an empty string, instead validation
does not kick-in for the list of pojos wrapped in the `Optional`.
If the value of `Optional` is a pojo or a primitive, validation rules are working fine.
I did a little bit more digging and tried to write my own value extractor:
public class OptionalListValueExtractor<T> implements
ValueExtractor<@ExtractedValue(type = List.class) Optional<List<T>>> {
@Override
public void extractValues(@ExtractedValue(type = List.class)
Optional<List<T>> originalValue, ValueReceiver valueReceiver) {
valueReceiver.value( null , originalValue.orElse( null ));
}
}
but when I register this class as a service, I get an exception with the cause:
Caused by: javax.validation.valueextraction.ValueExtractorDefinitionException: HV000225:
Only unbound wildcard type arguments are supported for the container type of the value
extractor: com.solace.maas.event.core.validation.OptionalListValueExtractor.
It seems it doesn't like that I have a class type specified in my Optional. But
without this generic, it is impossible to have the extractor working the right way.
Anyways, I think it is either a bug in HV or a functional efficiency.
Looking forward to your reply!
(
https://hibernate.atlassian.net/browse/HV-1794#add-comment?atlOrigin=eyJp...
) Add Comment (
https://hibernate.atlassian.net/browse/HV-1794#add-comment?atlOrigin=eyJp...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100133- sha1:ead1094 )