Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typesafe config: get as map

Tags:

scala

typesafe

googlesheets{
 dmkb_sheet = "1xEC8CPlKn654321wcoS_JB12345cPPiaA0M"
 other_sheet = "123isS0M30TH3R1D"
}

I would like to use something like myConfig.getAsMap("googlesheets") and get the two nested entries as a Map. No such method exists. So what is the easiest way to load the two nested entries as a Map?

like image 460
Jake Avatar asked Dec 06 '22 09:12

Jake


2 Answers

For some definition of easy you could use something like this:

val config = conf.atKey("googlesheets")
config.root.keySet.asScala.map(key ⇒ key → config.getString(key)).toMap

I would argue that it would be even easier to use a library for mapping configurations to case classes, like pureconfig

like image 118
emilianogc Avatar answered Dec 20 '22 04:12

emilianogc


OK, that was easy.

myConfig.getConfig("googlesheets").entrySet() does the trick

(I was fixated on the method having a "get" prefix, so missed it)

like image 20
Jake Avatar answered Dec 20 '22 04:12

Jake