繁体   English   中英

传递构造函数参数时未创建Yaml实例

[英]Yaml instance not created when constructor argument is passed

我正在使用snakeyml读取yml文件并将其加载到Java对象中。

问题:当我执行Yaml yml = new Yaml() ,会创建yml实例。 但是,当我传递构造函数参数时,不会创建yml实例。 我也没有看到例外。 这是完整的代码。

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;
}

在以下语句中退出代码:

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM