/** * Creates a new argument representing a generic set. * * @param type set element type * @param <T> set element type * @return The argument instance */ static <T> Argument<Set<T>> setOf(Class<T> type) { //noinspection unchecked return of((Class<Set<T>>) ((Class) Set.class), type); }
@Override public Argument<CompletableFuture> argumentType() { return Argument.of(CompletableFuture.class); }
/** * Creates a new argument representing a generic list. * * @param type list element type * @param <T> list element type * @return The argument instance */ static <T> Argument<List<T>> listOf(Class<T> type) { //noinspection unchecked return of((Class<List<T>>) ((Class) List.class), type); }
@Override public Argument<Publisher> argumentType() { return Argument.of(Publisher.class); }
/** * Decode the given type from the given {@link InputStream}. * * @param type The type * @param inputStream The input stream * @param <T> The generic type * @return The decoded result * @throws CodecException When the result cannot be decoded */ default <T> T decode(Class<T> type, InputStream inputStream) throws CodecException { return decode(Argument.of(type), inputStream); }
@SuppressWarnings("unchecked") @Override public <T1> Optional<T1> getBody(Class<T1> type) { return getBody(Argument.of(type)); }
/** * Create a simple {@link ConversionContext} for the given generic type variables. * * @param <T> type Generic * @param argument The argument * @return The conversion context */ static <T> ArgumentConversionContext<T> of(Class<T> argument) { return of(Argument.of(argument), null, null); }
/** * Returns a submap for all the keys with the given prefix. * * @param prefix The prefix * @param valueType The value type * @return The submap */ @SuppressWarnings("unchecked") default Map<String, V> subMap(String prefix, Class<V> valueType) { return subMap(prefix, Argument.of(valueType)); }
@Override public <T> Optional<T> getBody(Class<T> type) { if (type == null) { return Optional.empty(); } return getBody(Argument.of(type)); }
/** * Find a header and convert it to the given type. * * @param name The name of the header * @param requiredType The required type * @param <T> The generic type * @return If the header is presented and can be converted an optional of the value otherwise {@link Optional#empty()} */ default <T> Optional<T> getFirst(CharSequence name, Class<T> requiredType) { return getFirst(name, Argument.of(requiredType)); }
/** * Perform an HTTP request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher} and converting the response body to the specified type. * * @param request The {@link HttpRequest} to execute * @param bodyType The body type * @param <I> The request body type * @param <O> The response body type * @return The full {@link HttpResponse} object */ default <I, O> HttpResponse<O> exchange(HttpRequest<I> request, Class<O> bodyType) { return exchange(request, Argument.of(bodyType)); }
@Override public <I, O> Flowable<O> jsonStream(io.micronaut.http.HttpRequest<I> request, Class<O> type) { return jsonStream(request, io.micronaut.core.type.Argument.of(type)); }
/** * Perform an HTTP request for the given request object emitting the full HTTP response from returned * {@link Publisher} and converting the response body to the specified type. * * @param request The {@link HttpRequest} to execute * @param bodyType The body type * @param <I> The request body type * @param <O> The response body type * @return A {@link Publisher} that emits a result of the given type */ default <I, O> Publisher<O> retrieve(HttpRequest<I> request, Class<O> bodyType) { return retrieve(request, Argument.of(bodyType)); }
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @param requiredType The required type * @param <T> The value * @return An {@link Optional} of the value */ default @Nonnull <T> Optional<T> getValue(@Nonnull Class<? extends Annotation> annotation, @Nonnull String member, @Nonnull Class<T> requiredType) { ArgumentUtils.requireNonNull("requiredType", requiredType); return getValue(annotation, member, Argument.of(requiredType)); }
/** * Return the body as the given type. * * @param type The type of the body * @param <T> The generic type * @return An {@link Optional} of the type or {@link Optional#empty()} if the body cannot be returned as the given type */ default @Nonnull <T> Optional<T> getBody(@Nonnull Class<T> type) { ArgumentUtils.requireNonNull("type", type); return getBody(Argument.of(type)); }
/** * @return The return type as an argument */ default Argument<T> asArgument() { Collection<Argument<?>> values = getTypeVariables().values(); return Argument.of(getType(), values.toArray(new Argument[0])); }
/** * Resolve the given property for the given name. * * @param name The name * @param requiredType The required type * @param <T> The concrete type * @return An optional containing the property value if it exists and is able to be converted */ default <T> Optional<T> get(K name, Class<T> requiredType) { return get(name, ConversionContext.of(Argument.of(requiredType))); }
/** * Perform an HTTP GET request for the given request object emitting the full HTTP response from returned * {@link Publisher}. * * @param uri The request URI * @param bodyType The body type * @param <O> The response body type * @return A {@link Publisher} that emits the full {@link HttpResponse} object */ default <O> Publisher<HttpResponse<O>> exchange(String uri, Class<O> bodyType) { return exchange(HttpRequest.GET(uri), Argument.of(bodyType)); }
/** * Perform a GET request for the given request object emitting the full HTTP response from returned * {@link org.reactivestreams.Publisher}. * * @param uri The URI of the GET request * @param <O> The response body type * @param bodyType The body type * @return The full {@link HttpResponse} object */ default <O> HttpResponse<O> exchange(String uri, Class<O> bodyType) { return exchange(HttpRequest.GET(uri), Argument.of(bodyType)); }
/** * <p>Perform an HTTP GET request and receive data as a stream of SSE {@link Event} objects as they become available without blocking.</p> * <p> * <p>The downstream {@link org.reactivestreams.Subscriber} can regulate demand via the subscription</p> * * @param uri The request URI * @param eventType The event data type * @param <B> The event body type * @return A {@link Publisher} that emits an {@link Event} with the data represented by the eventType argument */ default <B> Publisher<Event<B>> eventStream(String uri, Class<B> eventType) { return eventStream(HttpRequest.GET(uri), Argument.of(eventType)); }