enum classes don't serialize properly when implementing ConfigurationSerializable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None
    • Environment:

      Java 15, Windows 10

    • This server is running CraftBukkit version git-Spigot-a19903d-009f0ba (MC: 1.16.4) (Implementing API version 1.16.4-R0.1-SNAPSHOT)
    • Yes

      enumerations that implement org.bukkit.configuration.serialization.ConfigurationSerializable aren't properly serialized to disk.

      Given a configurationserializable class like this:

      @SerializableAs("Hello")
      enum Hello implements ConfigurationSerializable {
          FOO,
          BAR;
      
          @Override
          public Map<String, Object> serialize() {
              return Collections.singletonMap("variant", name());
          }
      
          public static Hello deserialize(Map<String, Object> map) {
              return Hello.valueOf((String) map.get("variant"));
          }
      }
      

      and an onEnable like this:

          @Override
          public void onEnable() {
              ConfigurationSerialization.registerClass(Hello.class, "Hello");
      
              File dataFolder = getDataFolder();
              dataFolder.mkdirs();
      
              File saveFile = new File(dataFolder, "test.yml");
              try {
                  if (!saveFile.exists()) saveFile.createNewFile();
      
                  YamlConfiguration yamlConfiguration = new YamlConfiguration();
                  yamlConfiguration.set("hello", Hello.FOO);
                  yamlConfiguration.save(saveFile);
      
                  yamlConfiguration = YamlConfiguration.loadConfiguration(saveFile);
                  Hello hello = (Hello) yamlConfiguration.get("hello");
      
                  assert hello == Hello.FOO;
      
              } catch (IOException e) {
                  getLogger().log(Level.SEVERE, "could not save or load test.yml", e);
              }
          }
      

      ,

      it is expected that the contents of the test.yml savefile looks as follows:

      hello: 
        ==: Hello
        variant: 'FOO'
      

      but instead all that's there is:

      hello: !!com.example.Hello 'FOO'
      
      

            Assignee:
            Unassigned
            Reporter:
            Jan Boerman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: