-
Notifications
You must be signed in to change notification settings - Fork 368
Description
Since #4070 is closed, I am opening this issue as followup. We also have problem and I have created a reproducer project.
Reproducer project
git clone git@github.com:eguller/jersey-4077.git
There are two identical maven projects, one is using jersey 2.22.1 and other is 2.28
When run test cases, 2.22.1 is successful but 2.28 fails.
Problem statement
Issue is in org.glassfish.jersey.server.internal.inject.ParamConverterFactory
In 2.22.1, both converter providers and custom converter providers were added into list so order of providers is preserved. In this case our custom date parameter converter provider is the first element of providers set.
ParamConverterFactory(ServiceLocator locator) {
Set<ParamConverterProvider> customProviders = Providers.getCustomProviders(locator, ParamConverterProvider.class);
this.converterProviders.addAll(customProviders);
Set<ParamConverterProvider> providers = Providers.getProviders(locator, ParamConverterProvider.class);
providers.removeAll(customProviders);
this.converterProviders.addAll(providers);
}
In 2.28, copyProviders is used. Our custom provider (which is in providers) is the first element in providers, but when it is added into copyProviders, order is not preserved anymore.
Set<ParamConverterProvider> copyProviders = new HashSet<>(providers);
converterProviders = new ArrayList<>();
converterProviders.addAll(customProviders);
copyProviders.removeAll(customProviders);
converterProviders.addAll(copyProviders);
Provider is registered as below
register(new org.glassfish.jersey.internal.inject.AbstractBinder() {
@Override
protected void configure() {
bind(DateParamProvider.class).to(ParamConverterProvider.class).ranked(10);
}
});
Workaround
I found following workaround, but in my opinion 2.28 should work as in 2.22.1
If I use CustomAnnotationLiteral as below,
register(new org.glassfish.hk2.utilities.binding.AbstractBinder() {
@Override
protected void configure() {
bind(DateParamProvider.class).to(ParamConverterProvider.class).qualifiedBy(CustomAnnotationLiteral.INSTANCE);
}
});
then custom parameter converter is inserted into customProviders set instead of providers. In this case custom provider is always picked up first and problem is resolved.
In my opinion code should work as in v2.22.1, provider ranking which is given at registration should not be lost later on.