Can't load a bean using SnakeYAML

956 views Asked by At

I got this error

in 'reader', line 8, column 1:
time:
^
java.lang.NoSuchMethodException: com.test.Cfg$Time.()
in 'reader', line 9, column 3:
c: 5000
^

when I've tried to load a Cfg bean:

Yaml yml = new Yaml();
Cfg cfg = yml.loadAs(file, Cfg.class);

Here is my bean class

public class Cfg {   
    private Time time;

    // getters & setters ommited

    public class Time {
        private Long c;
        private Long r;

        // getters & setters ommited
    }
}

And my YML file

---
time:
  c: 5000
  r: 5000

I use Java 6.

How can I fix it?

1

There are 1 answers

2
Andrey On BEST ANSWER
  1. Cfg must be a JavaBean (add setter and getter for time)
  2. Time must be outside of Cfg, otherwise it has to have a link to Cfg instance (which is not configured in your YAML file)
  3. The parser is called SnakeYAML