A better way to load configuration of certain types with PureConfig in Scala

Reading Time: 2 minutes

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 !!!


Written by 

Rishi is a Lead Consultant, with experience of more than 7 years. Rishi is product focused developer who loves developing both front-end user interfaces and scalable back-end infrastructure. He is a good team player, quick learner and a humble person. He has good time management skills, aimed to give best results and fully dedicated towards his work & responsibilities. He is able to work as individual and as well as in team. He loves to share his knowledge, therefore he often writes technical blogs.

4 thoughts on “A better way to load configuration of certain types with PureConfig in Scala2 min read

Comments are closed.

%d bloggers like this: