1
mirror of https://github.com/CarmJos/EasyConfiguration.git synced 2026-06-05 11:54:13 +08:00

测试抽象类继承获取

This commit is contained in:
2022-04-18 22:38:49 +08:00
parent 0bda97d82a
commit 0d10a06547
5 changed files with 76 additions and 11 deletions
@@ -0,0 +1,16 @@
package config.model;
import org.jetbrains.annotations.NotNull;
public abstract class AbstractModel {
protected final @NotNull String name;
public AbstractModel(@NotNull String name) {
this.name = name;
}
public @NotNull String getName() {
return name;
}
}
@@ -0,0 +1,43 @@
package config.model;
import org.bspfsystems.yamlconfiguration.serialization.ConfigurationSerializable;
import org.bspfsystems.yamlconfiguration.serialization.SerializableAs;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import java.util.HashMap;
import java.util.Map;
@SerializableAs("SomeModel")
public class SomeModel extends AbstractModel implements ConfigurationSerializable {
int num;
public SomeModel(@NotNull String name, int num) {
super(name);
this.num = num;
}
@Override
public String toString() {
return "SomeModel{" +
"name='" + name + '\'' +
", num=" + num +
'}';
}
@Override
public @NotNull Map<String, Object> serialize() {
Map<String, Object> map = new HashMap<>();
map.put("name", name);
map.put("num", num);
return map;
}
@TestOnly
public static SomeModel deserialize(Map<String, ?> args) {
return new SomeModel((String) args.get("name"), (int) args.get("num"));
}
}
@@ -11,28 +11,19 @@ import java.util.Map;
import java.util.UUID;
@SerializableAs("TestModel")
public class TestModel implements ConfigurationSerializable {
public class TestModel extends AbstractModel implements ConfigurationSerializable {
public String name;
public UUID uuid;
public TestModel(String name, UUID uuid) {
this.name = name;
super(name);
this.uuid = uuid;
}
public void setName(String name) {
this.name = name;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public String getName() {
return name;
}
public UUID getUuid() {
return uuid;
}