Skip to content

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

Open
firasrg wants to merge 1 commit into
developfrom
firasrg/simplify-config-jsonproperty
Open

firasrg wants to merge 1 commit 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
@sonarqubecloud

Copy link
Copy Markdown

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

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