Search in sources :

Example 1 with AnnotatedArgumentBinder

use of io.micronaut.core.bind.annotation.AnnotatedArgumentBinder 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()));
        }
    }
}
Also used : HttpRequest(io.micronaut.http.HttpRequest) AnnotatedArgumentBinder(io.micronaut.core.bind.annotation.AnnotatedArgumentBinder) QueryValueArgumentBinder(io.micronaut.http.bind.binders.QueryValueArgumentBinder) AnnotatedArgumentBinder(io.micronaut.core.bind.annotation.AnnotatedArgumentBinder) ArgumentBinder(io.micronaut.core.bind.ArgumentBinder) QueryValue(io.micronaut.http.annotation.QueryValue)

Aggregations

ArgumentBinder (io.micronaut.core.bind.ArgumentBinder)1 AnnotatedArgumentBinder (io.micronaut.core.bind.annotation.AnnotatedArgumentBinder)1 HttpRequest (io.micronaut.http.HttpRequest)1 QueryValue (io.micronaut.http.annotation.QueryValue)1 QueryValueArgumentBinder (io.micronaut.http.bind.binders.QueryValueArgumentBinder)1