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 !!!
1 thought on “Deep dive into PureConfig types in Scala2 min read”
Reblogged this on Rishi Khandelwal.
Comments are closed.