记一次yaml转Java对象没有无参构造的异常
private void method(){
InputStream in;
try {
Yaml yaml = new Yaml();
in = this.getClass().getResourceAsStream("/ratelimiter-rule.yaml");
if (in != null) {
RuleConfig ruleConfig = yaml.loadAs(in, RuleConfig.class);
System.out.println(ruleConfig.toString());
Object obj =yaml.load(in);
System.out.println(obj);
}
} catch (Exception e) { e.printStackTrace(); }
}
如上为读取yaml文件转java对象代码;
共有 0 条评论