Load the default configuration and decode an instance at a specific path.
Load the default configuration and decode an instance at a specific path.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> case class HttpSettings(server: ServerSettings) scala> case class AppSettings(http: HttpSettings) scala> import com.typesafe.config.ConfigFactory scala> val config = ConfigFactory.load() scala> parser.decode[AppSettings](config) res0: Either[io.circe.Error, AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Load the default configuration and decode an instance at a specific path.
Load the default configuration and decode an instance at a specific path.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> case class HttpSettings(server: ServerSettings) scala> case class AppSettings(http: HttpSettings) scala> parser.decode[AppSettings]() res0: Either[io.circe.Error, AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Decode an instance supporting cats.ApplicativeError.
Decode an instance supporting cats.ApplicativeError.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> case class HttpSettings(server: ServerSettings) scala> case class AppSettings(http: HttpSettings) scala> import com.typesafe.config.ConfigFactory scala> val config = ConfigFactory.load() scala> import cats.effect.IO scala> parser.decodeF[IO, AppSettings](config) res0: cats.effect.IO[AppSettings] = IO(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Load default configuration and decode an instance supporting cats.ApplicativeError.
Load default configuration and decode an instance supporting cats.ApplicativeError.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> case class HttpSettings(server: ServerSettings) scala> case class AppSettings(http: HttpSettings) scala> import cats.effect.IO scala> parser.decodeF[IO, AppSettings]() res0: cats.effect.IO[AppSettings] = IO(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Load configuration from file and decode an instance.
Load configuration from file and decode an instance.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> case class HttpSettings(server: ServerSettings) scala> case class AppSettings(http: HttpSettings) scala> parser.decodeFile[AppSettings](new java.io.File("src/test/resources/application.conf")) res0: Either[io.circe.Error, AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Decode of an instance at a specific path.
Decode of an instance at a specific path.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> import com.typesafe.config.ConfigFactory scala> val config = ConfigFactory.load() scala> parser.decodePath[ServerSettings](config, "http.server") res0: Either[io.circe.Error, ServerSettings] = Right(ServerSettings(localhost,8080))
Load the default configuration and decode an instance.
Load the default configuration and decode an instance.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> parser.decodePath[ServerSettings]("http.server") res0: Either[io.circe.Error, ServerSettings] = Right(ServerSettings(localhost,8080))
Decode an instance supporting cats.ApplicativeError at a specific path.
Decode an instance supporting cats.ApplicativeError at a specific path.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> import com.typesafe.config.ConfigFactory scala> val config = ConfigFactory.load() scala> import cats.effect.IO scala> import io.circe.config.parser scala> parser.decodePathF[IO, ServerSettings](config, "http.server") res0: cats.effect.IO[ServerSettings] = IO(ServerSettings(localhost,8080))
Load default configuration and decode an instance supporting cats.ApplicativeError at a specific path.
Load default configuration and decode an instance supporting cats.ApplicativeError at a specific path.
scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> import cats.effect.IO scala> parser.decodePathF[IO, ServerSettings]("http.server") res0: cats.effect.IO[ServerSettings] = IO(ServerSettings(localhost,8080))
Utilities for parsing com.typesafe.config.Config sources to io.circe.Json as well as decoding to a specific type.
If you are working in something like cats.effect.IO, or some other type
F[_]that provides a cats.ApplicativeError, there're also decoders for loading such types.syntax.configDecoder for how to map io.circe.Json to com.typesafe.config.Config