Skip to content

@SerdeKey not respected when deserializing records #203

@TSRBerry

Description

@TSRBerry

I'm trying to use ObjectDeserializer to deserialize my config into a Record, but I get the following exception:

com.electronwill.nightconfig.core.serde.SerdeException: Could not deserialize this configuration to a record of type class com.example.config.ServerConfigData because the following components (entries) are missing: switchInterval

ServerConfigData is defined as follows:

public record ServerConfigData(
  @SerdeKey("switch_interval")
  @SerdeComment("A comment")
  int switchInterval,
  @SerdeComment("First comment")
  @SerdeComment("Second comment")
  Map<String, List<UUID>> groups
)

It seems that the @SerdeKey annotations are not respected during deserialization.
Am I doing something wrong or is that a genuine bug?

Currently I'm reading the config as follows:

public final class ConfigManager {
  private CommentedFileConfig serverConfig;

  public ConfigManager() {
   Path configDir = null; // Some path
    serverConfig = CommentedFileConfig
      .builder(configDir.resolve("server_config.toml"))
      .defaultResource("/config/default_server_config.toml")
      .preserveInsertionOrder()
      .autoreload()
      .build();
    serverConfig.load();
  }

  public ServerConfigData getServerConfig() {
    return ObjectDeserializer.standard().deserializeToRecord(serverConfig, ServerConfigData.class);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions