I am using snakeyml to read yml file and load it in Java objects.
Issue: When I do a Yaml yml = new Yaml()
, yml instance is created. But when I pass the constructor argument, the yml instance is not created. I don't see an exception either. This is the complete code.
private static YamlConfig readStatsConfig()
throws IOException {
InputStream input = new FileInputStream(new File(configFile));
Constructor constructor = new Constructor(YamlConfig.class);
TypeDescription description = new TypeDescription(YamlConfig.class);
description.putListPropertyType("resources", YamlConfig.Resource.class);
constructor.addTypeDescription(description);
TypeDescription description = new TypeDescription(
YamlConfig.Resource.class);
description.putListPropertyType("stats", YamlConfig.StatsInfo.class);
constructor.addTypeDescription(description);
Yaml yaml = new Yaml(constructor);
YamlConfig cfg = (YamlConfig) yaml.load(input);
mainLogger.info(cfg);
return cfg;
}
Code exit in the following statement:
Yaml yaml = new Yaml(constructor);
I fixed the issue by excluding snakeyml dependency in TestNG JARs. All we need to do is to add the following in the project POM has dependency with TestNG.
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
<type>jar</type>
<exclusions>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.