簡體   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