Deep dive into PureConfig types in Scala

Reading Time: 2 minutes

Folks, I am back with some more exploration on PureConfig. This time we will talk about the types. For types, we have following two things to discuss:

  • New supported types
  • Override behaviour for types

 

In this blog, we will discuss only the first one i.e. New supported types

New supported types: PureConfig does not support all kind of types. For ex, classes that are not case classes are not supported out-of-the-box

In order to read an instance of a given type T from a config, PureConfig needs to have in scope in implicit instance of ConfigReader[T] for that type.

You can see above that Year is not a case class. Therefore, this won’t compile because there’s no ConfigReader instance for Year:

PureConfig can be extended to support those types. To do so, an instance for the ConfigReader type class must be provided.

First, define a ConfigReader instance in implicit scope:

Now when we load the config, it will be loaded successfully :

You can check the list of supported types here. For more details on custom supported types, visit here.

You can get the full code here.

We will discuss the second point i.e. Override behaviour for types in next blog. Stay tuned for the same.

I hope you will enjoy the reading and will have worth for you.

Happy Blogging !!!

Happy Coding !!!


KNOLDUS-advt-sticker

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.

1 thought on “Deep dive into PureConfig types in Scala2 min read

Comments are closed.

%d bloggers like this: