Skip to content

Commit 3113177

Browse files
committed
fix round two
1 parent 67041fd commit 3113177

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/main/java/net/discordjug/javabot/data/config/ReflectionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private static Field findDeclaredField(Class<?> cl, String name) throws NoSuchFi
118118
* @throws IllegalAccessException If the field cannot be set.
119119
*/
120120
public static Object set(@NotNull Field field, @NotNull Object parent, @NotNull String s) throws IllegalAccessException {
121-
Object value = GsonUtils.fromJson(s, field.getType());
121+
Object value = GsonUtils.fromJson(s, field.getGenericType());
122122
field.set(parent, value);
123123
return value;
124124
}

src/main/java/net/discordjug/javabot/systems/configuration/SetConfigSubcommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.discordjug.javabot.systems.configuration;
22

3+
import com.google.gson.JsonSyntaxException;
34
import net.discordjug.javabot.annotations.AutoDetectableComponentHandler;
45
import net.discordjug.javabot.data.config.BotConfig;
56
import net.discordjug.javabot.data.config.GuildConfig;
@@ -80,8 +81,8 @@ public void handleModal(ModalInteractionEvent event, List<ModalMapping> values)
8081
try {
8182
guildConfig.set(property, valueString);
8283
Responses.success(event, "Configuration Updated", "The property `%s` has been set to `%s`.", property, valueString).queue();
83-
} catch (UnknownPropertyException e) {
84-
Responses.error(event, "Property not found: %s", property).queue();
84+
} catch (UnknownPropertyException | JsonSyntaxException e) {
85+
Responses.error(event, "Error while setting new value").queue();
8586
}
8687
}
8788

src/main/java/net/discordjug/javabot/util/GsonUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.io.Reader;
88
import java.io.Writer;
9+
import java.lang.reflect.Type;
910
import java.util.regex.Pattern;
1011

1112
/**
@@ -20,11 +21,11 @@ public class GsonUtils {
2021
.enableComplexMapKeySerialization()
2122
.create();
2223

23-
public static <T> T fromJson(String json, Class<T> type) {
24+
public static <T> T fromJson(Reader json, Class<T> type) {
2425
return gson.fromJson(json, type);
2526
}
2627

27-
public static <T> T fromJson(Reader json, Class<T> type) {
28+
public static String fromJson(String json, Type type) {
2829
return gson.fromJson(json, type);
2930
}
3031

@@ -35,5 +36,4 @@ public static String toJson(Object object) {
3536
public static void toJson(Object object, Writer writer) {
3637
gson.toJson(object, writer);
3738
}
38-
3939
}

0 commit comments

Comments
 (0)