aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2022-11-14 08:11:34 +0000
committerisXander <xandersmith2008@gmail.com>2022-11-14 08:11:34 +0000
commitb03eac307a881e1363eeb9492dd5430f68baf40b (patch)
tree3fd43ae3e87b00628238790dd6c44caf30fd1378 /src/main
parent29770a651daa38a18b99eecd5ecf90cf90ceeb0f (diff)
downloadYetAnotherConfigLib-b03eac307a881e1363eeb9492dd5430f68baf40b.tar.gz
YetAnotherConfigLib-b03eac307a881e1363eeb9492dd5430f68baf40b.tar.bz2
YetAnotherConfigLib-b03eac307a881e1363eeb9492dd5430f68baf40b.zip
require ConfigEntry annotation for GsonConfigInstance
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/dev/isxander/yacl/config/ConfigEntry.java11
-rw-r--r--src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java14
2 files changed, 24 insertions, 1 deletions
diff --git a/src/main/java/dev/isxander/yacl/config/ConfigEntry.java b/src/main/java/dev/isxander/yacl/config/ConfigEntry.java
new file mode 100644
index 0000000..7f04c33
--- /dev/null
+++ b/src/main/java/dev/isxander/yacl/config/ConfigEntry.java
@@ -0,0 +1,11 @@
+package dev.isxander.yacl.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface ConfigEntry {
+}
diff --git a/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java b/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java
index 6f517cc..5d19e48 100644
--- a/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java
+++ b/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java
@@ -43,7 +43,7 @@ public class GsonConfigInstance<T> extends ConfigInstance<T> {
super(configClass);
this.path = path;
this.gson = builder
- .excludeFieldsWithModifiers(Modifier.TRANSIENT)
+ .setExclusionStrategies(new ConfigExclusionStrategy())
.registerTypeHierarchyAdapter(Text.class, new Text.Serializer())
.registerTypeHierarchyAdapter(Style.class, new Style.Serializer())
.registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter())
@@ -81,6 +81,18 @@ public class GsonConfigInstance<T> extends ConfigInstance<T> {
return this.path;
}
+ private static class ConfigExclusionStrategy implements ExclusionStrategy {
+ @Override
+ public boolean shouldSkipField(FieldAttributes fieldAttributes) {
+ return fieldAttributes.getAnnotation(ConfigEntry.class) == null;
+ }
+
+ @Override
+ public boolean shouldSkipClass(Class<?> aClass) {
+ return false;
+ }
+ }
+
public static class ColorTypeAdapter implements JsonSerializer<Color>, JsonDeserializer<Color> {
@Override
public Color deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {