1
mirror of https://github.com/CarmJos/EasyConfiguration.git synced 2026-06-04 10:38:19 +08:00

feat(adapter): Support complex ParameterizedType's serialize & deserialize.

This commit is contained in:
2025-06-26 02:24:42 +08:00
parent 8c1214612a
commit 8766b4d77b
+14 -2
View File
@@ -24,6 +24,10 @@ public class RecordTest {
Arrays.asList( Arrays.asList(
new User("Alice", 30), new User("Alice", 30),
new User("Bob", 25) new User("Bob", 25)
),
Map.of(
"Cloud", new Connection("cloud.example.com", 443),
"Local", new Connection("127.0.0.1", 8080)
) )
)); ));
@@ -51,7 +55,7 @@ public class RecordTest {
System.out.println("Another Users: " + user.name() + ", Age: " + user.age()); System.out.println("Another Users: " + user.name() + ", Age: " + user.age());
} }
// printMap(holder.config().asMap(), 0); printMap(holder.config().asMap(), 0);
// try { // try {
// List<User> parsed = holder.deserialize(ValueType.ofList(User.class), holder.config().getList("val.users")); // List<User> parsed = holder.deserialize(ValueType.ofList(User.class), holder.config().getList("val.users"));
@@ -75,6 +79,9 @@ public class RecordTest {
for (User user : ConfigB.VAL.resolve().users()) { for (User user : ConfigB.VAL.resolve().users()) {
System.out.println("Another Users: " + user.name() + ", Age: " + user.age()); System.out.println("Another Users: " + user.name() + ", Age: " + user.age());
} }
ConfigB.VAL.resolve().connections.forEach((k, v) -> {
System.out.println("Connection " + k + ": " + v.address() + ":" + v.port());
});
} }
@@ -82,7 +89,12 @@ public class RecordTest {
record User(String name, int age) { record User(String name, int age) {
} }
record Device(String id, String name, UUID serial, Chip chip, List<User> users) { record Connection(String address, int port) {
}
record Device(String id, String name, UUID serial, Chip chip,
List<User> users,
Map<String, Connection> connections) {
} }
record Chip(String id, String serialNumber) { record Chip(String id, String serialNumber) {