In this blog we will discuss about the better way of loading the configuration of certain types. Now a days we use typesafe config for the same purpose. PureConfig also uses typesafe config internally but also provides the better way of doing this.
PureConfig is not a configuration library, it can be seen as a better front-end for the existing libraries. It uses the Typesafe Config library for loading raw configurations and then uses the raw configurations to do its magic.
The goal of PureConfig is to create at compile-time the boilerplate necessary to load a configuration of a certain type. In other words, you define what to load and PureConfig provides how to load it.
To use the PurConfig, we need to add dependency in build.sbt for scala 2.11, 2.12:
Now define the config in application.conf file :
You can see above, there are different types of values present in config i.e. List, Map, String, Int
Now Define the scala types for config to be converted :
By analyzing config and the case class you will notice that field’s name in config is in Kebab case (full-name) while in case class it is in camel case (fullName). This is the default behavior. We will see the customize behavior for defining field’s name in the coming blogs.
Now load the config :
That’s it. Hope you enjoy the reading.
You can get the full code here.
Happy Blogging !!!
4 thoughts on “A better way to load configuration of certain types with PureConfig in Scala2 min read”
Reblogged this on Anurag Srivastava.
Reblogged this on Rishi Khandelwal.
I have developed lightweight alternative: https://github.com/andr83/scalaconfig
Comments are closed.