-
Notifications
You must be signed in to change notification settings - Fork 1.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
Refactor ConversionService
to remove mutable operations from ConversionService.SHARED
#8156
Conversation
fyi this will conflict with #8100, I made a similar ConversionService change in DefaultHttpClient there |
@dstepanov can you resolve the conflicts |
core/src/main/java/io/micronaut/core/convert/MutableConversionService.java
Show resolved
Hide resolved
I think we can remove concurrent maps in the default implementation. I have measured it can get us 50% more throughput. The idea would be only to allow adding a new converter via |
* @param <S> The source generic type | ||
* @param <T> The target generic type | ||
*/ | ||
<S, T> void addConverter(@NonNull Class<S> sourceType, @NonNull Class<T> targetType, @NonNull Function<S, T> typeConverter); |
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.
Return MutableConversionService
to make the API fluent
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.
Do you want to have it generic like it was before?
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.
Makes sense
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'm looking at it again, and I don't like to have it in this way. There are zero usages of chaining in the current codebase. The registration API defines this signature: void register(ConversionService<?> conversionService)
which prevents to do the chaining. IMHO the generic parameter only makes the code ugly, and the chaining is not very important in this case. I would prefer not to have it. WDYT @micronaut-projects/core-developers ?
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.
It is probably fine without it but the generic argument remains a potentially large source of breaking changes
http/src/main/java/io/micronaut/http/converters/SharedHttpConvertersRegistrar.java
Show resolved
Hide resolved
* @author Graeme Rocher | ||
* @since 1.0 | ||
*/ | ||
public interface ConversionService<Impl extends ConversionService> { | ||
public interface ConversionService { |
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'm concerned about the removal of the generic type argument here as it likely to break a lot of end user code. Is this a necessary change? What is the justification?
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.
It was only used for the mutable add
methods, now those methods are gone so the generic parameter is unused.
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.
It does mean though that any place a user injected ConversionService<?>
will break which might be a significant breaking change. Thoughts @sdelamo ?
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.
Users might need to modify their code anyway if relying on the shared conversion service.
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.
Our docs use ConversionService<?>
in examples. Still I never liked that generic type argument, so my +1 to remove it if it's not needed
SonarCloud Quality Gate failed. |
Fixes #7657
Hopefully replaced all the possible usages of
ConversionService.SHARED
.Some use cases cannot work after this change:
The detached request body is being converted:
Not sure if it's something that is even make sense, the fix now it to use this: