Skip to content

Commit

Permalink
#1034 Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GuusLieben committed Dec 22, 2023
1 parent e56037c commit 77c231f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private <T> T createOrUpdate(ComponentKey<T> key, T instance, ConfigurationObjec
Option<T> configuration;
Class<T> type = instance == null
? key.type()
: TypeUtils.adjustWildcards(instance.getClass(), Class.class);
: TypeUtils.getClass(instance);

if (instance == null) {
configuration = this.propertyHolder.get(configurationObject.prefix(), type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.dockbox.hartshorn.config.FileFormats;
import org.dockbox.hartshorn.config.ObjectMapper;
import org.dockbox.hartshorn.config.ObjectMappingException;
import org.dockbox.hartshorn.util.TypeUtils;
import org.dockbox.hartshorn.util.GenericType;

import jakarta.inject.Singleton;

Expand All @@ -49,10 +49,10 @@ public void process(ApplicationContext context, Set<ConfigurationURIContext> con
}

try {
Map<String, Object> cache = TypeUtils.adjustWildcards(context.get(ObjectMapper.class)
Map<String, Object> cache = context.get(ObjectMapper.class)
.fileType(format)
.read(uri, Map.class)
.orElseGet(HashMap::new), Map.class);
.read(uri, new GenericType<Map<String, Object>>() {})
.orElseGet(HashMap::new);

context.log().debug("Located " + cache.size() + " properties in " + uri.getPath());
context.get(PropertyHolder.class).set(cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,9 @@ public static boolean isAssignable(Class<?> source, Class<?> target) {
}
return source.isPrimitive() && TypeUtils.isPrimitiveWrapper(target, source);
}

public static <T> Class<T> getClass(T instance) {
//noinspection unchecked
return (Class<T>) instance.getClass();
}
}

0 comments on commit 77c231f

Please sign in to comment.