From 36c2172658ba1a29242d3fc9934e964d957b76d9 Mon Sep 17 00:00:00 2001 From: Firas Regaieg Date: Fri, 20 Nov 2026 20:42:40 +0100 Subject: [PATCH 1/5] Refactor: simplify Config JSON binding by dropping redundant @JsonProperty names/values --- application/build.gradle | 7 ++ .../org/togetherjava/tjbot/config/Config.java | 89 ++++++++----------- 2 files changed, 43 insertions(+), 53 deletions(-) diff --git a/application/build.gradle b/application/build.gradle index 51477929dd..dd1104c488 100644 --- a/application/build.gradle +++ b/application/build.gradle @@ -67,6 +67,8 @@ dependencies { implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion" implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jacksonVersion" implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion" + implementation "com.fasterxml.jackson.module:jackson-module-parameter-names:$jacksonVersion" + implementation "com.sigpwned:jackson-modules-java17-sealed-classes:2.19.0.0" implementation 'com.github.freva:ascii-table:1.13.0' @@ -87,6 +89,11 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" implementation "com.openai:openai-java:$chatGPTVersion" + +} + +tasks.withType(JavaCompile).configureEach { + options.compilerArgs << '-parameters' } application { diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index d465f09800..02e63a35a6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; import java.io.IOException; import java.nio.file.Path; @@ -56,64 +57,45 @@ public final class Config { @SuppressWarnings("ConstructorWithTooManyParameters") @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - private Config(@JsonProperty(value = "token", required = true) String token, - @JsonProperty(value = "githubApiKey", required = true) String githubApiKey, - @JsonProperty(value = "databasePath", required = true) String databasePath, - @JsonProperty(value = "projectWebsite", required = true) String projectWebsite, - @JsonProperty(value = "discordGuildInvite", required = true) String discordGuildInvite, - @JsonProperty(value = "modAuditLogChannelPattern", - required = true) String modAuditLogChannelPattern, - @JsonProperty(value = "modMailChannelPattern", - required = true) String modMailChannelPattern, - @JsonProperty(value = "projectsChannelPattern", - required = true) String projectsChannelPattern, - @JsonProperty(value = "mutedRolePattern", required = true) String mutedRolePattern, - @JsonProperty(value = "heavyModerationRolePattern", - required = true) String heavyModerationRolePattern, - @JsonProperty(value = "softModerationRolePattern", - required = true) String softModerationRolePattern, - @JsonProperty(value = "tagManageRolePattern", - required = true) String tagManageRolePattern, - @JsonProperty(value = "excludeCodeAutoDetectionRolePattern", - required = true) String excludeCodeAutoDetectionRolePattern, - @JsonProperty(value = "suggestions", required = true) SuggestionsConfig suggestions, - @JsonProperty(value = "quarantinedRolePattern", - required = true) String quarantinedRolePattern, - @JsonProperty(value = "scamBlocker", required = true) ScamBlockerConfig scamBlocker, - @JsonProperty(value = "wolframAlphaAppId", required = true) String wolframAlphaAppId, - @JsonProperty(value = "helpSystem", required = true) HelpSystemConfig helpSystem, - @JsonProperty(value = "mediaOnlyChannelPattern", - required = true) String mediaOnlyChannelPattern, - @JsonProperty(value = "blacklistedFileExtension", - required = true) List blacklistedFileExtension, - @JsonProperty(value = "logInfoChannelWebhook", - required = true) String logInfoChannelWebhook, - @JsonProperty(value = "logErrorChannelWebhook", - required = true) String logErrorChannelWebhook, - @JsonProperty(value = "githubReferencingEnabledChannelPattern", - required = true) String githubReferencingEnabledChannelPattern, - @JsonProperty(value = "githubRepositories", - required = true) List githubRepositories, - @JsonProperty(value = "openaiApiKey", required = true) String openaiApiKey, - @JsonProperty(value = "sourceCodeBaseUrl", required = true) String sourceCodeBaseUrl, - @JsonProperty(value = "jshell", required = true) JShellConfig jshell, - @JsonProperty(value = "memberCountCategoryPattern", - required = true) String memberCountCategoryPattern, - @JsonProperty(value = "helperPruneConfig", - required = true) HelperPruneConfig helperPruneConfig, + private Config(@JsonProperty(required = true) String token, + @JsonProperty(required = true) String githubApiKey, + @JsonProperty(required = true) String databasePath, + @JsonProperty(required = true) String projectWebsite, + @JsonProperty(required = true) String discordGuildInvite, + @JsonProperty(required = true) String modAuditLogChannelPattern, + @JsonProperty(required = true) String modMailChannelPattern, + @JsonProperty(required = true) String projectsChannelPattern, + @JsonProperty(required = true) String mutedRolePattern, + @JsonProperty(required = true) String heavyModerationRolePattern, + @JsonProperty(required = true) String softModerationRolePattern, + @JsonProperty(required = true) String tagManageRolePattern, + @JsonProperty(required = true) String excludeCodeAutoDetectionRolePattern, + @JsonProperty(required = true) SuggestionsConfig suggestions, + @JsonProperty(required = true) String quarantinedRolePattern, + @JsonProperty(required = true) ScamBlockerConfig scamBlocker, + @JsonProperty(required = true) String wolframAlphaAppId, + @JsonProperty(required = true) HelpSystemConfig helpSystem, + @JsonProperty(required = true) String mediaOnlyChannelPattern, + @JsonProperty(required = true) List blacklistedFileExtension, + @JsonProperty(required = true) String logInfoChannelWebhook, + @JsonProperty(required = true) String logErrorChannelWebhook, + @JsonProperty(required = true) String githubReferencingEnabledChannelPattern, + @JsonProperty(required = true) List githubRepositories, + @JsonProperty(required = true) String openaiApiKey, + @JsonProperty(required = true) String sourceCodeBaseUrl, + @JsonProperty(required = true) JShellConfig jshell, + @JsonProperty(required = true) String memberCountCategoryPattern, + @JsonProperty(required = true) HelperPruneConfig helperPruneConfig, @JsonProperty(value = "featureBlacklist", required = true) FeatureBlacklistConfig featureBlacklistConfig, @JsonProperty(value = "rssConfig", required = true) RSSFeedsConfig rssFeedsConfig, - @JsonProperty(value = "selectRolesChannelPattern", - required = true) String selectRolesChannelPattern, - @JsonProperty(value = "quoteBoardConfig", - required = true) QuoteBoardConfig quoteBoardConfig, + @JsonProperty(required = true) String selectRolesChannelPattern, + @JsonProperty(required = true) QuoteBoardConfig quoteBoardConfig, @JsonProperty(value = "roleApplicationSystem", required = true) RoleApplicationSystemConfig roleApplicationSystemConfig, - @JsonProperty(value = "topHelpers", required = true) TopHelpersConfig topHelpers, - @JsonProperty(value = "dynamicVoiceChatConfig", - required = true) DynamicVoiceChatConfig dynamicVoiceChatConfig, - @JsonProperty(value = "tavilyApiKey", required = true) String tavilyApiKey) { + @JsonProperty(required = true) TopHelpersConfig topHelpers, + @JsonProperty(required = true) DynamicVoiceChatConfig dynamicVoiceChatConfig, + @JsonProperty(required = true) String tavilyApiKey) { this.token = Objects.requireNonNull(token); this.githubApiKey = Objects.requireNonNull(githubApiKey); this.databasePath = Objects.requireNonNull(databasePath); @@ -164,6 +146,7 @@ private Config(@JsonProperty(value = "token", required = true) String token, */ public static Config load(Path path) throws IOException { return new ObjectMapper().registerModule(new JavaTimeModule()) + .registerModule(new ParameterNamesModule()) .readValue(path.toFile(), Config.class); } From 6bd0e3eefa93d577b03fa09642b384785921e6e9 Mon Sep 17 00:00:00 2001 From: Firas Regaieg Date: Tue, 24 Nov 2026 19:35:48 +0100 Subject: [PATCH 2/5] CR1: update and improve the javadoc of Config; --- .../org/togetherjava/tjbot/config/Config.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index 02e63a35a6..1dac2ef96a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -14,7 +14,21 @@ /** - * Configuration of the application. Create instances using {@link #load(Path)}. + * Configuration of the application. + *

+ * Instances are created from the JSON configuration file by {@link #load(Path)}. Constructor + * parameter names correspond directly to property names in the JSON where possible, so an explicit + * JSON property name is redundant in those cases. For example, the {@code token} parameter already + * maps to the {@code "token"} property. + *

+ * Matching parameter names are preserved by compiling with the {@code -parameters} flag and enabled + * through the Jackson parameter-names module. Property names must be specified explicitly only when + * they differ from the corresponding configuration class or constructor parameter name. + * + * @see PR #1602 + * @see Java + * compiler {@code -parameters} option */ public final class Config { private final String token; From 9c84a26843a5333cd709510bf2efdf29c4b22b85 Mon Sep 17 00:00:00 2001 From: Firas Regaieg Date: Thu, 26 Nov 2026 17:34:58 +0100 Subject: [PATCH 3/5] CR2: add inline comment explanation about -parameters with Config.java; --- application/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/build.gradle b/application/build.gradle index dd1104c488..304f7f4aba 100644 --- a/application/build.gradle +++ b/application/build.gradle @@ -93,7 +93,7 @@ dependencies { } tasks.withType(JavaCompile).configureEach { - options.compilerArgs << '-parameters' + options.compilerArgs << '-parameters' // So Jackson can construct Config.java without explicit @JsonProperty(value = "...") } application { From 3ee418708f77735e8cf31f01bef6ab69d0e76b5b Mon Sep 17 00:00:00 2001 From: Firas Regaieg Date: Thu, 26 Nov 2026 20:12:06 +0100 Subject: [PATCH 4/5] rollback Config.java javadoc to original --- .../org/togetherjava/tjbot/config/Config.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index 1dac2ef96a..02e63a35a6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -14,21 +14,7 @@ /** - * Configuration of the application. - *

- * Instances are created from the JSON configuration file by {@link #load(Path)}. Constructor - * parameter names correspond directly to property names in the JSON where possible, so an explicit - * JSON property name is redundant in those cases. For example, the {@code token} parameter already - * maps to the {@code "token"} property. - *

- * Matching parameter names are preserved by compiling with the {@code -parameters} flag and enabled - * through the Jackson parameter-names module. Property names must be specified explicitly only when - * they differ from the corresponding configuration class or constructor parameter name. - * - * @see PR #1602 - * @see Java - * compiler {@code -parameters} option + * Configuration of the application. Create instances using {@link #load(Path)}. */ public final class Config { private final String token; From ef528babb1aa4f884e40e6a76e661cc385b246f3 Mon Sep 17 00:00:00 2001 From: Firas Regaieg Date: Fri, 27 Nov 2026 19:32:40 +0100 Subject: [PATCH 5/5] add inline comment about -parameters usage for Jackson --- .../src/main/java/org/togetherjava/tjbot/config/Config.java | 1 + 1 file changed, 1 insertion(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/config/Config.java b/application/src/main/java/org/togetherjava/tjbot/config/Config.java index 02e63a35a6..33df790824 100644 --- a/application/src/main/java/org/togetherjava/tjbot/config/Config.java +++ b/application/src/main/java/org/togetherjava/tjbot/config/Config.java @@ -17,6 +17,7 @@ * Configuration of the application. Create instances using {@link #load(Path)}. */ public final class Config { + // Jackson uses the param names by default, since we compile with -parameters private final String token; private final String githubApiKey; private final String databasePath;