isXander / isXander/YetAnotherConfigLib
Inherited @SerialEntry fields are not saved in json
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 155
- Forks
- 68
- PR merge metrics
- No merged PRs in 30d
Description
In the previous version of yacl, where config instances were built like so:
GsonConfigInstance.createBuilder(c)
.setPath( Path.of(CONFIG_PATH,"cfg.json")).build();
If there was an abstract class A with a @ConfigEntry field, and it was extended by class B, then GsonConfigInstance.createBuilder(B.class) would, when built and saved, end up saving an instance of the @ConfigEntry fields in the abstract class. However, in the new version, where a config class handler is created as follows:
ConfigClassHandler.createBuilder(c)
Inherited fields are not saved in the config. Is this intended behavior for the new version?
A simple mixin can be used to emulate the behavior of previous versions:
@Mixin(targets = "dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl")
public class ConfigClassHandlerImplMixin {
private static List<Field> getAllFields(Class<?> type) {
List<Field> fields = new ArrayList<Field>();
for (Class<?> c = type; c != null; c = c.getSuperclass()) {
fields.addAll(Arrays.asList(c.getDeclaredFields()));
}
return fields;
}
@Redirect(method= "<init>(Ljava/lang/Class;Lnet/minecraft/util/Identifier;Ljava/util/function/Function;)V",
at = @At(
value = "INVOKE", target = "Ljava/lang/Class;getDeclaredFields()[Ljava/lang/reflect/Field;"
))
public Field[] redir(Class instance){
List<Field> fs = getAllFields(instance);
return fs.toArray(new Field[fs.size()]);
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ConfigClassHandler.createBuilder(c) and ConfigClassHandlerImpl’s constructor, especially the Class.getDeclaredFields() call shown in the issue. Reproduce the abstract A and extended B example and compare it with the previous version’s handling of inherited @ConfigEntry fields. Done when the intended behavior is confirmed and saving a B instance consistently handles inherited fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100