From 56c9eaca00f8cd8109f0a90f52d6b238403f0268 Mon Sep 17 00:00:00 2001 From: Marcin Stawowczyk Date: Fri, 9 Jun 2023 00:28:06 +0200 Subject: [PATCH 1/6] fix object on save clears cache When an object is saved it will remove cache. --- src/main/java/pl/mikigal/config/serializer/Serializer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pl/mikigal/config/serializer/Serializer.java b/src/main/java/pl/mikigal/config/serializer/Serializer.java index 6fec820..0007737 100644 --- a/src/main/java/pl/mikigal/config/serializer/Serializer.java +++ b/src/main/java/pl/mikigal/config/serializer/Serializer.java @@ -44,6 +44,7 @@ public final void serialize(String path, Object object, BukkitConfiguration conf } this.saveObject(path, (T) object, configuration); + configuration.addToCache(path, object); } /** From ca576be589dbf80452d7fdeca479d564e8262053 Mon Sep 17 00:00:00 2001 From: Marcin Stawowczyk Date: Fri, 9 Jun 2023 00:29:34 +0200 Subject: [PATCH 2/6] allow usage ConfigOptional annotation on proporties --- src/main/java/pl/mikigal/config/annotation/ConfigOptional.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pl/mikigal/config/annotation/ConfigOptional.java b/src/main/java/pl/mikigal/config/annotation/ConfigOptional.java index 766e61d..c031cfe 100644 --- a/src/main/java/pl/mikigal/config/annotation/ConfigOptional.java +++ b/src/main/java/pl/mikigal/config/annotation/ConfigOptional.java @@ -11,7 +11,7 @@ * @since 1.0 * @author Mikołaj Gałązka */ -@Target({ElementType.METHOD}) +@Target({ElementType.FIELD, ElementType.METHOD}) @Retention(value = RetentionPolicy.RUNTIME) public @interface ConfigOptional { } From e39a16498fa52012e47ae6f7617bd08a70792e26 Mon Sep 17 00:00:00 2001 From: Marcin Stawowczyk Date: Fri, 9 Jun 2023 00:32:34 +0200 Subject: [PATCH 3/6] add ConfigOptional on custom DTO proporties --- .../universal/UniversalObjectSerializer.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java b/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java index 4fdf0b2..c234e3d 100644 --- a/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java +++ b/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java @@ -17,7 +17,7 @@ * Class must have default constructor (no-args). * @see Serializer * @see Serializable - * @since 1.1.7 + * @since 1.1.8 * @author Mikołaj Gałązka */ public class UniversalObjectSerializer extends Serializer { @@ -34,6 +34,12 @@ protected void saveObject(String path, Serializable object, BukkitConfiguration field.setAccessible(true); Object value = field.get(object); + + // Check if field is optional + if (field.isAnnotationPresent(ConfigOptional.class)) { + field.setAccessible(false); + if (value == null) continue; + } try { if (TypeUtils.isSimpleType(field.getType())) { @@ -88,6 +94,13 @@ public Serializable deserialize(String path, BukkitConfiguration configuration) } field.setAccessible(true); + + String fullpath = path + "." + configuration.getNameStyle().format(field.getName()); + + // Check if field is optional + if (field.isAnnotationPresent(ConfigOptional.class)) { + if (configuration.get(fullpath) == null) continue; + } Class type = field.getType(); if (TypeUtils.isSimpleType(type)) { From 0fa94881e5480733b5e5d099ad3ee2b7e3db7037 Mon Sep 17 00:00:00 2001 From: mikigal Date: Fri, 9 Jun 2023 01:44:09 +0200 Subject: [PATCH 4/6] Fixed missing import --- .../config/serializer/universal/UniversalObjectSerializer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java b/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java index c234e3d..b46aebf 100644 --- a/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java +++ b/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java @@ -1,6 +1,7 @@ package pl.mikigal.config.serializer.universal; import pl.mikigal.config.BukkitConfiguration; +import pl.mikigal.config.annotation.ConfigOptional; import pl.mikigal.config.exception.InvalidConfigException; import pl.mikigal.config.exception.MissingSerializerException; import pl.mikigal.config.serializer.Serializer; From 356e543bce557c8cf478a5eca8fa8d17d0cc1284 Mon Sep 17 00:00:00 2001 From: mikigal Date: Fri, 9 Jun 2023 01:45:38 +0200 Subject: [PATCH 5/6] Reformatted code --- .../serializer/universal/UniversalObjectSerializer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java b/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java index b46aebf..e38b755 100644 --- a/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java +++ b/src/main/java/pl/mikigal/config/serializer/universal/UniversalObjectSerializer.java @@ -39,7 +39,9 @@ protected void saveObject(String path, Serializable object, BukkitConfiguration // Check if field is optional if (field.isAnnotationPresent(ConfigOptional.class)) { field.setAccessible(false); - if (value == null) continue; + if (value == null) { + continue; + } } try { @@ -100,7 +102,9 @@ public Serializable deserialize(String path, BukkitConfiguration configuration) // Check if field is optional if (field.isAnnotationPresent(ConfigOptional.class)) { - if (configuration.get(fullpath) == null) continue; + if (configuration.get(fullpath) == null){ + continue; + } } Class type = field.getType(); From 8d7d89129b8ffca1335dcba98271c45072d35486 Mon Sep 17 00:00:00 2001 From: mikigal Date: Fri, 9 Jun 2023 01:47:17 +0200 Subject: [PATCH 6/6] Bumped version to 1.2.4 --- README.MD | 4 ++-- build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.MD b/README.MD index dccff0e..600c282 100644 --- a/README.MD +++ b/README.MD @@ -21,7 +21,7 @@ maven { url = 'https://repo.mikigal.pl/releases' } -compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.3' +compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.4' ``` #### Maven @@ -34,7 +34,7 @@ compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.3' pl.mikigal ConfigAPI - 1.2.3 + 1.2.4 compile ``` diff --git a/build.gradle b/build.gradle index df27b4f..befd0c3 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'pl.mikigal' -version '1.2.3' +version '1.2.4' publishing { repositories {