Skip to content

Commit

Permalink
Improve the ControllerConstraintHandlerTest to accept more HttpReques…
Browse files Browse the repository at this point in the history
…t body types (#10909)
  • Loading branch information
andriy-dmytruk authored Jun 17, 2024
1 parent 39818ad commit 3744f17
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.micronaut.core.annotation.Introspected;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.convert.value.ConvertibleValues;
import io.micronaut.core.type.Argument;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
Expand Down Expand Up @@ -191,6 +192,10 @@ Optional<Map> constraintsEx(ConstraintViolationException e, HttpRequest<?> reque
password = credentials.getPassword();
} else if (obj instanceof CredentialsWithNonNull credentials) {
password = credentials.getPassword();
} else if (obj instanceof Map<?, ?> map) {
password = map.get("password") == null ? null : map.get("password").toString();
} else if (obj instanceof ConvertibleValues<?> values) {
password = values.get("password", String.class).orElse(null);
}
return password != null ? Optional.of(Map.of("password", password)) : Optional.empty();
}
Expand Down

0 comments on commit 3744f17

Please sign in to comment.