-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve MessageBodyHandler selection #9347
Conversation
andriy-dmytruk
commented
May 29, 2023
- Use the message body writer and reader order in selection
- For writers, only select those that can consume a particular type
db6a810
to
1463761
Compare
newMediaTypeQualifier(type, mediaTypes, Produces.class) | ||
// Do not put the type here since we are looking for writers that can process the type | ||
// but beanLocator will provide types that can be injected into the searched type | ||
Argument.of(MessageBodyWriter.class), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think this change is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you moving this logic to reduce down below? what is the actual change here? I dont understand what youre fixing and why it's fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change is the difference between reader and writer:
- A
MessageBodyReader<T>
would haveT
as a return type therefore for a typeP
we would be looking for anyMessageBodyReader<T>
such thatT extends P
. - A
MessageBodyWriter<T>
would haveT
as a method parameter therefore for a typeP
we would be looking for anyMessageBodyWriter<T>
such thatP extends T
.
The main difference is how the isAssignableFrom
method is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so basically, the change is to make writer matching covariant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and prevent the selection of a body writer for contravariant types, which would throw an error when calling the method.
http/src/main/java/io/micronaut/http/body/DefaultMessageBodyHandlerRegistry.java
Show resolved
Hide resolved
http/src/main/java/io/micronaut/http/body/DefaultMessageBodyHandlerRegistry.java
Outdated
Show resolved
Hide resolved
http/src/main/java/io/micronaut/http/body/DefaultMessageBodyHandlerRegistry.java
Outdated
Show resolved
Hide resolved
1463761
to
7534a9a
Compare
http/src/main/java/io/micronaut/http/body/DefaultMessageBodyHandlerRegistry.java
Show resolved
Hide resolved
Looks good. Thanks, Graeme! |
Kudos, SonarCloud Quality Gate passed! |