Skip to content

Commit

Permalink
fix primitive noop
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Sep 22, 2024
1 parent ed84249 commit 0ea1a02
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

/** Builds and caches the ValidationAdapter adapters for DValidator. */
final class CoreAdapterBuilder {
@SuppressWarnings("rawtypes")
public static final ValidationAdapter NOOP = (type, req, propertyName) -> true;

private static final Set<Class<?>> DEFAULT_GROUP = Set.of(Default.class);
private final DValidator context;
Expand Down Expand Up @@ -106,7 +104,7 @@ <T> ValidationAdapter<T> buildAnnotation(
}
}
// unknown annotations have noop
return NOOP;
return NoOpValidator.INSTANCE;
}

record Request(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.avaje.validation.core;

import io.avaje.validation.adapter.ValidationAdapter;
import io.avaje.validation.adapter.ValidationRequest;

class NoOpValidator implements ValidationAdapter, ValidationAdapter.Primitive {

public static final NoOpValidator INSTANCE = new NoOpValidator();

@Override
public boolean validate(Object value, ValidationRequest req, String propertyName) {

return true;
}

@Override
public Primitive primitive() {
return this;
}

@Override
public boolean validate(boolean value, ValidationRequest req, String propertyName) {

return true;
}

@Override
public boolean validate(byte value, ValidationRequest req, String propertyName) {

return true;
}

@Override
public boolean validate(char value, ValidationRequest req, String propertyName) {

return true;
}

@Override
public boolean validate(double value, ValidationRequest req, String propertyName) {

return true;
}

@Override
public boolean validate(float value, ValidationRequest req, String propertyName) {

return true;
}

@Override
public boolean validate(int value, ValidationRequest req, String propertyName) {

return true;
}

@Override
public boolean validate(long value, ValidationRequest req, String propertyName) {

return true;
}

@Override
public boolean validate(short value, ValidationRequest req, String propertyName) {

return true;
}
}

0 comments on commit 0ea1a02

Please sign in to comment.