Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check a partial key in typesafe config

I am using typesafe config to read some initial configurations.

Is there a way to check if a part of key is present in the type config. For example I have the below config:

foo {
    bar {
        x = 42
        y = 92
    }    
 }

Here I want to check if my conf contains any configuration for foo.bar I don't care if x or y both are present of either one is present.

I just want to check if configuration for bar is present in config. Is it possible?

like image 287
Ambuj Jauhari Avatar asked Mar 17 '23 06:03

Ambuj Jauhari


1 Answers

Config has method for checking if a path exists

config.hasPath("foo.bar");

Given the following

foo {
    bar {
        x = 42
    }
}

System.out.println(config.hasPath("foo.bar"));
System.out.println(config.hasPath("foo.bar.x"));

I get

true
true

If I remove x = 42 I get

true
false
like image 181
tddmonkey Avatar answered Mar 18 '23 19:03

tddmonkey