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

Table of contents
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 tech enthusiast with having around 10 years of experience who loves to solve complex problems with pure quality. He is a functional programmer and loves to learn new trending technologies. His leadership skill is well prooven and has delivered multiple distributed applications with high scalability and availability by keeping the Reactive principles in mind. He is well versed with Scala, Akka, Akka HTTP, Akka Streams, Java8, Reactive principles, Microservice architecture, Async programming, functional programming, distributed systems, AWS, docker.

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

Comments are closed.