mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
[Fix] Handle JsonSyntaxException
[Fix] Type check
This commit is contained in:
1 parent
a550f67f00
commit
602dd1efd7
2 files changed
+9
-3
No files matched your search
@@ -74,9 +74,9 @@ public abstract class Module {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Optional<Value<T>> getValue(String name) {
|
||||
public <T> Optional<Value<T>> getValue(String name, Class<T> type) {
|
||||
for (Value<?> v : values) {
|
||||
if (v.getName().equalsIgnoreCase(name)) {
|
||||
if (v.getName().equalsIgnoreCase(name) && type.isInstance(v.getValue())) {
|
||||
return Optional.of((Value<T>) v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.xiaozhou233.orangex.module.value;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -21,7 +22,12 @@ public abstract class Value<T> {
|
||||
}
|
||||
|
||||
public void fromJson(JsonElement element) {
|
||||
setValue(gson.fromJson(element, getValueClass()));
|
||||
try {
|
||||
setValue(gson.fromJson(element, getValueClass()));
|
||||
} catch (JsonSyntaxException e) {
|
||||
System.out.println("Failed to parse json for value " + name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Class<T> getValueClass();
|
||||
|
||||
Reference in new issue
Block a user