Yaml dumping entire object?

Discussion in 'Plugin Development' started by RcExtract, Jun 24, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    RcExtract

    I am coding a game plugin. I want to save properties of a custom object to the config file, but it seems to be hard cuz the properties contains a list of another custom object which contains a lot of properties which some of them are lists of Location. Ik I can save the entire object, but how can the yaml dumper detects the properties of an object, and how can I choose to save some properties but not some?
     
  2. @RcExtract
    If you want to have one of your own objects be YAML-serialized, you need to implement the ConfigurationSerializable interface. If you implement the methods, you can probably figure out how to do it.
     
  3. Offline

    RcExtract

    public class Demo {
    private String name;
    private String desc;
    public Demo(String name, String desc) {
    this.name = name;
    this.desc = desc;
    }
    }
    public class Example {
    public static void main(String[] args) {
    System.out.println(new Yaml().dump(new Demo("hi", "bye")));
    }
    }

    The output is:

    !!Demo
    name: "hi"
    desc: "bye"

    How can the dump method do this?
     
  4. Offline

    Zombie_Striker

    @RcExtract
    Implement ConfigurationSerializable. After that, add a method for serializing the class, and add all the variables and fields into a hashmap which is saved to the config. Then, create a new constructor that takes in the hashmap from the serializing method, and take all the values from the hashmap and reset the fields.
     
Thread Status:
Not open for further replies.

Share This Page