Skip to content

Commit

Permalink
Handle primitive HTTP client responses
Browse files Browse the repository at this point in the history
Fixes issue #10698
  • Loading branch information
kevin-wise committed Apr 9, 2024
1 parent 5a876a0 commit 9ba172a
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.micronaut.http.codec.MediaTypeCodec;
import io.micronaut.inject.BeanDefinition;
import io.micronaut.inject.BeanType;
import io.micronaut.inject.beans.AbstractInitializableBeanIntrospection;
import io.micronaut.inject.qualifiers.Qualifiers;
import jakarta.inject.Singleton;

Expand Down Expand Up @@ -75,20 +76,28 @@ public final class DefaultMessageBodyHandlerRegistry extends RawMessageBodyHandl
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
protected <T> MessageBodyReader<T> findReaderImpl(Argument<T> type, List<MediaType> mediaTypes) {
final Argument<T> finalType;
if (type.isPrimitive()) {
Class<?> wrapperType = type.getWrapperType();
finalType = (Argument<T>) Argument.of(wrapperType, type.getAnnotationMetadata());
} else {
finalType = type;
}

Collection<BeanDefinition<MessageBodyReader>> beanDefinitions = beanLocator.getBeanDefinitions(
Argument.of(MessageBodyReader.class, type),
Argument.of(MessageBodyReader.class, finalType),
newMediaTypeQualifier(Argument.of(MessageBodyReader.class), mediaTypes, Consumes.class)
);
if (beanDefinitions.size() == 1) {
return beanLocator.getBean(beanDefinitions.iterator().next());
} else {
List<BeanDefinition<MessageBodyReader>> exactMatch = beanDefinitions.stream()
List<BeanDefinition<MessageBodyReader>> exactMatch = beanDefinitions.stream()
.filter(d -> {
List<Argument<?>> typeArguments = d.getTypeArguments(MessageBodyReader.class);
if (typeArguments.isEmpty()) {
return false;
} else {
return type.equalsType(typeArguments.get(0));
return finalType.equalsType(typeArguments.get(0));
}
}).toList();
if (exactMatch.size() == 1) {
Expand Down

0 comments on commit 9ba172a

Please sign in to comment.