parser
io.circe.config.parser$
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.
Attributes
- See also:
syntax.configDecoder for how to map io.circe.Json to com.typesafe.config.Config
- Example:
scala> import com.typesafe.config.ConfigFactory scala> import io.circe.config.parser scala> val config = ConfigFactory.parseString("server { host = localhost, port = 8080 }") scala> val json: Either[io.circe.ParsingFailure, io.circe.Json] = parser.parse(config) scala> json.map(_.noSpaces).getOrElse("Parse failure") res0: String = {"server":{"port":8080,"host":"localhost"}} scala> import io.circe.generic.auto._ scala> case class ServerSettings(host: String, port: Int) scala> case class AppSettings(server: ServerSettings) scala> parser.decode[AppSettings](config) res1: Either[io.circe.Error, AppSettings] = Right(AppSettings(ServerSettings(localhost,8080))) scala> parser.decodePath[ServerSettings](config, "server") res2: Either[io.circe.Error, ServerSettings] = Right(ServerSettings(localhost,8080)) scala> import cats.effect.IO scala> parser.decodePathF[IO, ServerSettings](config, "server") res3: cats.effect.IO[ServerSettings] = IO(ServerSettings(localhost,8080))- Source:
- parser.scala
- Graph
- Supertypes
- Self type
- parser.type