diff --git a/core/pom.xml b/core/pom.xml
index 75f007e..107ff1a 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -5,7 +5,7 @@
configured-parent
cc.carm.lib
- 4.1.6
+ 4.1.7-SNAPSHOT
4.0.0
diff --git a/core/src/main/java/cc/carm/lib/configuration/adapter/ValueAdapterRegistry.java b/core/src/main/java/cc/carm/lib/configuration/adapter/ValueAdapterRegistry.java
index 2a833c3..674fa90 100644
--- a/core/src/main/java/cc/carm/lib/configuration/adapter/ValueAdapterRegistry.java
+++ b/core/src/main/java/cc/carm/lib/configuration/adapter/ValueAdapterRegistry.java
@@ -2,12 +2,13 @@ package cc.carm.lib.configuration.adapter;
import cc.carm.lib.configuration.function.DataFunction;
import cc.carm.lib.configuration.source.ConfigurationHolder;
+import cc.carm.lib.configuration.source.section.ConfigureSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.*;
public class ValueAdapterRegistry {
@@ -108,20 +109,106 @@ public class ValueAdapterRegistry {
public T deserialize(@NotNull ConfigurationHolder> holder, @NotNull ValueType type, @Nullable Object source) throws Exception {
if (source == null) return null; // Null check
- if (type.isInstance(source)) return type.cast(source); // Not required to deserialize
- ValueAdapter adapter = adapterOf(type);
- if (adapter == null) throw new RuntimeException("No adapter for type " + type);
- return adapter.parse(holder, type, source);
+ if (!(type.getType() instanceof ParameterizedType) && type.isInstance(source)) {
+ return type.cast(source); // Not required to deserialize
+ }
+
+ ValueAdapter adapter = adapterOf(type); // Try to find an existed adapter for the type
+ if (adapter != null) {
+ return adapter.parse(holder, type, source);
+ } // If no adapter found, we will try to handle the type manually
+
+ if (type.getRawType().isArray()) { // For arrays.
+ List> list = deserializeList(holder, type, source);
+ Object[] array = (Object[]) java.lang.reflect.Array.newInstance(type.getRawType().getComponentType(), list.size());
+ for (int i = 0; i < list.size(); i++) {
+ array[i] = deserialize(holder, type.getRawType().getComponentType(), list.get(i));
+ }
+ return type.cast(array);
+ } else if (type.getType() instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) type.getType();
+ Type rawType = pt.getRawType();
+ Type[] typeArgs = pt.getActualTypeArguments();
+ if (rawType == List.class || rawType == Collection.class || rawType == ArrayList.class) {
+ return type.cast(new ArrayList<>(deserializeList(holder, ValueType.of(typeArgs[0]), source)));
+ } else if (rawType == Set.class || rawType == HashSet.class) {
+ return type.cast(new HashSet<>(deserializeList(holder, ValueType.of(typeArgs[0]), source)));
+ } else if (rawType == Map.class || rawType == LinkedHashMap.class) {
+ Map, ?> map;
+ if (source instanceof Map, ?>) {
+ map = (Map, ?>) source;
+ } else if (source instanceof ConfigureSection) {
+ map = ((ConfigureSection) source).asMap();
+ } else {
+ throw new IllegalArgumentException("Cannot deserialize to Map from " + source.getClass());
+ }
+ Map