Skip to content

Refactor: Simplify Config JSON binding by dropping redundant @JsonProperty names - #1602

Merged
Zabuzard merged 5 commits into
developfrom
firasrg/simplify-config-jsonproperty
Nov 30, 2026
Merged

Zabuzard merged 5 commits into
developfrom
firasrg/simplify-config-jsonproperty

Conversation

@firasrg

@firasrg firasrg commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Removes the explicit value from every @JsonProperty in Config's @JsonCreator constructor. Property names are now taken from the constructor parameter names.

Before

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
private Config(
  @JsonProperty(value = "foo", required = true) String foo,
  @JsonProperty(value = "bar", required = true) String bar, 
  // .. others
)

After

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
private Config(
  @JsonProperty(required = true) String foo,
  @JsonProperty(required = true) String bar
  // .. others
)

How

  • application/build.gradle: compile with -parameters, add jackson-module-parameter-names
  • Config: register ParameterNamesModule on the ObjectMapper
  • JSON keys now follow Java parameter names, so renaming a parameter changes the config.json key. Behavior is otherwise unchanged; existing config files load as before.
  • Tested by running the app and loading the existing config.

@firasrg
firasrg requested a review from a team as a code owner November 20, 2026 19:54
@Zabuzard
Zabuzard requested a balanced review from Copilot November 20, 2026 19:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the configuration-deserialization simplification.

No open issues 🎉

What changed in this PR

Simplifies Config JSON deserialization by deriving property names from constructor parameters while preserving explicit mappings where JSON keys differ.

Changes:

  • Removes redundant @JsonProperty names while retaining required-property checks.
  • Registers Jackson’s ParameterNamesModule for configuration loading.
  • Adds the matching Jackson dependency and enables Java’s -parameters compiler option.
File Description
application/​src/​main/​java/​org/​togetherjava/​tjbot/​config/​Config.java Simplifies property annotations and registers parameter-name support.
application/​build.gradle Adds the Jackson module and preserves constructor parameter names during compilation.

Review effort: Balanced

@Tais993 Tais993 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be documented in the class.

Currently, hard-coded property names make it much easier for beginners to understand how this works. If some simple Javadoc is added that explains how adding a parameter will automatically resolve its value from the config, that would be great

@Zabuzard Zabuzard left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not a fan of this part:
options.compilerArgs << '-parameters'
it makes the compilation chain and the project "more complex/fragile" from a setup perspective.

but at the moment i cant say how common/problematic/heavy-weight this is. would need to do some research

@firasrg

firasrg commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@Tais993 FWIW, not all fields have been changed. I've kept some of them as they are (e,g: roleApplicationSystem) because their names differ between the config.json file and the corresponding Java field.

@Tais993

Tais993 commented Nov 25, 2026

Copy link
Copy Markdown
Member

im not a fan of this part: options.compilerArgs << '-parameters' it makes the compilation chain and the project "more complex/fragile" from a setup perspective.

but at the moment i cant say how common/problematic/heavy-weight this is. would need to do some research

Spring does it in exactly the same way, using the Spring Boot Gradle plugin which adds it automatically.

Tais993
Tais993 previously approved these changes Nov 25, 2026

@Tais993 Tais993 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code and the quality is fine. Using -parameters is alright and the usual approach.

I'm just still not sure on the direction, as I'm not sure about the actual benefit on this change. For that reason I'll let @Zabuzard make the final decision but a LGTM for now

Comment thread application/build.gradle Resolved
@Tais993
Tais993 requested a review from Zabuzard November 27, 2026 10:39
@sonarqubecloud

Copy link
Copy Markdown

@Zabuzard
Zabuzard merged commit d1a3648 into develop Nov 30, 2026
11 checks passed
@Zabuzard
Zabuzard deleted the firasrg/simplify-config-jsonproperty branch November 30, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants