Ihor Mochurad (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ccb2fc...
) *updated* an issue
Hibernate Validator (
https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiMTFiMTIwOTVlM...
) / Bug (
https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiMTFiMTIw...
) HV-1794 (
https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiMTFiMTIw...
) Optional containing a list of items is not being validated (
https://hibernate.atlassian.net/browse/HV-1794?atlOrigin=eyJpIjoiMTFiMTIw...
)
Change By: Ihor Mochurad (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ccb2fc...
)
As a user of Hibernate Validator, I would expect that a field like
` {noformat} private Optional<List<ConsumerGroupDTO>> consumerGroups; `
{noformat}
where ` * ConsumerGroupDTO ` * is the following pojo:
{code:java}
@Data
@SuperBuilder
@NoArgsConstructor
public class ConsumerGroupDTO extends ConsumerDTO {
private @NotEmpty String consumerGroupId;
private boolean simpleConsumerGroup;
}
{code}
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:
{code:java}
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));
}
}
{code}
but when I register this class as a service, I get an exception with the cause:
{code:java}
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.
{code}
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 )