Skip to content
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

PAYARA-2258 Implement support for Converters with Generics #2365

Merged
merged 2 commits into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import fish.payara.nucleus.microprofile.config.spi.PayaraConfig;
import java.lang.reflect.Member;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.DeploymentException;
Expand Down Expand Up @@ -69,7 +71,7 @@ public static final Object getGenericProperty(InjectionPoint ip) {
Object result = null;
ConfigProperty property = ip.getAnnotated().getAnnotation(ConfigProperty.class);
PayaraConfig config = (PayaraConfig) ConfigProvider.getConfig();
Class<?> type = (Class<?>) ip.getType();

String name = property.name();
if (name.isEmpty()) {
// derive the property name from the injection point
Expand All @@ -86,7 +88,14 @@ public static final Object getGenericProperty(InjectionPoint ip) {
sb.append(ip.getMember().getName());
name = sb.toString();
}
result = config.getValue(name, property.defaultValue(),type);

Type type = ip.getType();
if (type instanceof Class) {
result = config.getValue(name, property.defaultValue(),(Class<?>)type);
} else if ( type instanceof ParameterizedType) {
result = config.getValue(name, (Class<?>)((ParameterizedType)type).getRawType());
}

if (result == null) {
throw new DeploymentException("Microprofile Config Property " + property.name() + " can not be found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,23 @@ private <T> Converter<T> getConverter(Class<T> propertyType) {
} else if (type.equals(boolean.class)) {
type = Boolean.class;
}
return converters.get(type);
Converter<T> converter = converters.get(type);


if (converter == null) {
// search for a matching raw type
for (Type type1 : converters.keySet()) {
if (type1 instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType)type1;
if (ptype.getRawType().equals(propertyType)) {
converter = converters.get(type1);
break;
}
}
}
}

return converter;
}

private int getPriority(Converter converter) {
Expand Down