Merged
Conversation
…Field.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Config class to improve field organization, implement selective serialization, and preserve unknown fields for backward compatibility.
- Reorganizes
Configfields with better logical grouping and organization - Implements selective serialization that only writes modified fields to avoid storing default values
- Adds support for preserving unknown fields during deserialization to prevent config corruption between different HMCL versions
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| DirtyTracker.java | New utility for tracking which Observable properties have been modified |
| ObservableField.java | New reflection-based utility for handling JavaFX Observable properties with Gson serialization |
| TypeUtils.java | Utility class copied from Gson for advanced type resolution and manipulation |
| Config.java | Major refactoring with field reorganization, custom adapter for selective serialization, and unknown field preservation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Comment on lines
+791
to
+797
| FIELDS.forEach(field -> { | ||
| JsonElement value = values.remove(field.getSerializedName()); | ||
| if (value != null) { | ||
| config.tracker.markDirty(field.get(config)); | ||
| field.deserialize(config, value, context); | ||
| } | ||
| }); |
There was a problem hiding this comment.
This logic doesn't handle fields with alternate names defined by @SerializedName annotation. The code only checks for the primary serialized name but ignores the alternate names, which could cause deserialization to fail for fields using alternate names.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本 PR
Config的字段,使未来我们添加字段更容易;Config的序列化Config仅会序列化被修改过的字段,不会将字段默认值写入配置文件,以便我们未来调整这些字段的默认值。Config在反序列化时会保存所有未知字段,避免旧版本 HMCL 损坏新版本 HMCL 的配置文件