OkaeriPoland / okaeri-configs

Simple Java/POJO config library written with love and Lombok
MIT License
77 stars 11 forks source link

Comments inside subconfigs from collections and maps don't work #33

Closed Brikster closed 2 years ago

Brikster commented 2 years ago

Describe the bug

Created yaml file doesn't have comments on the field with subconfigs. Here is the code example:

 // That's field in OkaeriConfig with Map of subconfigs (another OkaeriConfig impl.)
 private Map<String, ChatNotificationChannelConfig> channels = new LinkedHashMap<String, ChatNotificationChannelConfig>() {{
    put("default", new ChatNotificationChannelConfig());
    put("donate", new ChatNotificationChannelConfig(
       30,
       Lists.newArrayList("some message"),
       false,
       false
    ));
 }};

 @Getter
 @AllArgsConstructor
 @NoArgsConstructor
 @SuppressWarnings("FieldMayBeFinal")
 @Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE)
 public static class ChatNotificationChannelConfig extends OkaeriConfig {

    @Comment("Time in seconds for periodically broadcasting")
    private int time = 60;

    @Comment
    @Comment({"line1", "line2"})
    private List<String> messages = Lists.newArrayList(
     "&8===================================\n" +
     "text\n" +
     "&8==================================="
    );

    @Comment
    @Comment("Enable this, if you want to restrict channel by permission")
    private boolean permissionRequired = false;

    @Comment
    @Comment("Enable this, if you want messages to be sent randomly")
    private boolean randomOrder = false;

 }

Config is loaded with:

ConfigManager.create(configClass, config -> {
    config.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesCommons(), new SerdesBukkit());
    config.withBindFile(dataFolderPath.resolve(fileName));
    config.withRemoveOrphans(true);
    config.saveDefaults();
    config.load(true);
});

The final yaml file looks like this (there are no comments):

chat:
  enable: true
  channels:
    default:
      time: 60
      messages:
      - |-
        &8===================================
        text
        &8===================================
      permission-required: false
      random-order: false
    donate:
      time: 30
      messages:
      - some message
      permission-required: false
      random-order: false
dasavick commented 2 years ago

Expected behavior mentioned in the README of the yaml-bukkit module. Duplicate of https://github.com/OkaeriPoland/okaeri-configs/issues/17.