<>
is an alias to orElse
.
<>
is an alias to orElse
.
Try this
(configSource
), and if it fails, try that
(configSource
)
For example:
Given three configSources, configSource1
, configSource2
and configSource3
, such that
configSource1 and configSource2 will only have id
and configSource3
act as a global fall-back source.
The following config tries to fetch Id
from configSource1, and if fails, it tries configSource2
,
and if both fails it gets from configSource3
. Age
will be fetched only from configSource3
.
val config = (string("Id") from (configSource1 orElse configSource2) |@| int("Age"))(Person.apply, Person.unapply) read(config from configSource3)
Convert the keys before it is queried from ConfigSource.
Convert the keys before it is queried from ConfigSource.
For example:
Given two configSources, configSource1
and configSource2
, such that
configSource1 can have uppercase ID and lowercase age,
and configSource2 can have lowercase ID and uppercase age.
The following solution will not help here, as you would imagine.
config.mapKeys(_.toUpperCase) from configSource1 orElse config.mapKeys(_.toLowerCase) from configSource2)
A correct solution here would be the following, indicating the fact configSources
act differently for
different fields.
val idSource = configSource1.convertKeys(_.toUpperCase) <> configSource2.convertKeys(_.toLowerCase) val ageSource = configSource1.convertKeys(_.toLowerCase) <> configSource2.convertKeys(_.toUpperCase) val config = (string("Id") from idSource |@| int("Age") from ageSource)(Person.apply, Person.unapply) read(config)
Try this
(configSource
), and if it fails, try that
(configSource
)
Try this
(configSource
), and if it fails, try that
(configSource
)
For example:
Given three configSources, configSource1
, configSource2
and configSource3
, such that
configSource1 and configSource2 will only have id
and configSource3
act as a global fall-back source.
The following config tries to fetch Id
from configSource1, and if fails, it tries configSource2
,
and if both fails it gets from configSource3
. Age
will be fetched only from configSource3
.
val config = (string("Id") from (configSource1 orElse configSource2) |@| int("Age"))(Person.apply, Person.unapply) read(config from configSource3)