Skip to content

Use isOmitted rather than isPresent in ValueExtractor to allow validation of null arguments #842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ArgumentValueValueExtractor implements ValueExtractor<Argumen

@Override
public void extractValues(ArgumentValue<?> argumentValue, ValueReceiver receiver) {
if (argumentValue.isPresent()) {
if (!argumentValue.isOmitted()) {
receiver.value(null, argumentValue.value());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ void shouldRaiseValidationErrorForAnnotatedParams() {

BiConsumer<Object, Object[]> validator3 = validateFunction(MyBean.class, "myValidArgumentValue");
assertViolation(() -> validator3.accept(bean, new Object[] {ArgumentValue.ofNullable("")}), "myValidArgumentValue.arg0");

// Validate that an explicit null value is validated.
assertViolation(() -> validator3.accept(bean, new Object[] {ArgumentValue.ofNullable(null)}), "myValidArgumentValue.arg0");
}

@Test
void shouldNotRaiseValidationErrorForOmittedArgumentValue() {
MyBean bean = new MyBean();

// Validate that an omitted value is allowed.
BiConsumer<Object, Object[]> validator3 = validateFunction(MyBean.class, "myValidArgumentValue");
validator3.accept(bean, new Object[] {ArgumentValue.omitted()});
}

@Test
Expand Down