use of io.micronaut.core.bind.ArgumentBinder in project micronaut-core by micronaut-projects.
the class WebSocketStateBinderRegistry method findArgumentBinder.
@Override
public <T> Optional<ArgumentBinder<T, WebSocketState>> findArgumentBinder(Argument<T> argument, WebSocketState source) {
Optional<ArgumentBinder<T, HttpRequest<?>>> argumentBinder = requestBinderRegistry.findArgumentBinder(argument, source.getOriginatingRequest());
if (argumentBinder.isPresent()) {
ArgumentBinder<T, HttpRequest<?>> adapted = argumentBinder.get();
boolean isParameterBinder = adapted instanceof AnnotatedArgumentBinder && ((AnnotatedArgumentBinder) adapted).getAnnotationType() == QueryValue.class;
if (!isParameterBinder) {
return Optional.of((context, source1) -> adapted.bind(context, source.getOriginatingRequest()));
}
}
ArgumentBinder binder = byType.get(argument.getType());
if (binder != null) {
// noinspection unchecked
return Optional.of(binder);
} else {
ConvertibleValues<Object> uriVariables = source.getSession().getUriVariables();
if (uriVariables.contains(argument.getName())) {
return Optional.of((context, s) -> () -> uriVariables.get(argument.getName(), argument));
} else {
return Optional.of((context, s) -> (ArgumentBinder.BindingResult<T>) queryValueArgumentBinder.bind((ArgumentConversionContext<Object>) context, s.getOriginatingRequest()));
}
}
}
Aggregations