Packages

  • package root
    Definition Classes
    root
  • package io
    Definition Classes
    root
  • package circe
    Definition Classes
    io
  • package config

    circe-config: A Typesafe config wrapper powered by circe.

    circe-config: A Typesafe config wrapper powered by circe.

    Definition Classes
    circe
    Example:
    1. scala> import com.typesafe.config.ConfigFactory
      scala> import io.circe.generic.auto._
      scala> import io.circe.config.syntax._
      
      scala> case class ServerSettings(host: String, port: Int, ssl: Option[String])
      scala> case class HttpSettings(server: ServerSettings, version: Double)
      scala> case class AppSettings(http: HttpSettings)
      
      scala> val config = ConfigFactory.parseString("http { version = 1.1, server { host = localhost, port = 8080 } }")
      
      scala> config.as[ServerSettings]("http.server")
      res0: Either[io.circe.Error, ServerSettings] = Right(ServerSettings(localhost,8080,None))
      
      scala> config.as[HttpSettings]("http")
      res1: Either[io.circe.Error, HttpSettings] = Right(HttpSettings(ServerSettings(localhost,8080,None),1.1))
      
      scala> config.as[AppSettings]
      res2: Either[io.circe.Error, AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080,None),1.1)))
      
      scala> import cats.effect.IO
      scala> config.asF[IO, AppSettings]
      res3: IO[AppSettings] = IO(AppSettings(HttpSettings(ServerSettings(localhost,8080,None),1.1)))
      
      scala> import io.circe.config.parser
      scala> val settings = parser.decodeF[IO, AppSettings]()
      scala> settings.unsafeRunSync()
      res4: AppSettings = AppSettings(HttpSettings(ServerSettings(localhost,8080,None),1.1))
    Note

    Limitations for numerical types: Typesafe config uses Java's int, long and double types to represent numbers. In some cases, double values may be represented internally as long after a roundtrip since the HOCON formatting is not stable. Also, precision may be lost when converting from circe's JsonNumber to Typesafe config's number representation (as can be seen in the test for the printer laws).

  • parser
  • printer
  • syntax

object parser extends 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.

Source
parser.scala
Example:
  1. 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))
See also

syntax.configDecoder for how to map io.circe.Json to com.typesafe.config.Config

Linear Supertypes
Parser, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. parser
  2. Parser
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def decode[A](config: Config)(implicit arg0: Decoder[A]): Either[Error, A]

    Load the default configuration and decode an instance at a specific path.

    Load the default configuration and decode an instance at a specific path.

    Example:
    1. 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))))
  7. final def decode[A]()(implicit arg0: Decoder[A]): Either[Error, A]

    Load the default configuration and decode an instance at a specific path.

    Load the default configuration and decode an instance at a specific path.

    Example:
    1. 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))))
  8. final def decode[A](input: String)(implicit arg0: Decoder[A]): Either[Error, A]
    Definition Classes
    Parser
  9. final def decodeAccumulating[A](config: Config)(implicit arg0: Decoder[A]): ValidatedNel[Error, A]
  10. final def decodeAccumulating[A](input: String)(implicit arg0: Decoder[A]): ValidatedNel[Error, A]
    Definition Classes
    Parser
  11. final def decodeF[F[_], A](config: Config)(implicit arg0: Decoder[A], ev: ApplicativeError[F, Throwable]): F[A]

    Decode an instance supporting cats.ApplicativeError.

    Decode an instance supporting cats.ApplicativeError.

    Example:
    1. 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))))
  12. final def decodeF[F[_], A]()(implicit arg0: Decoder[A], ev: ApplicativeError[F, Throwable]): F[A]

    Load default configuration and decode an instance supporting cats.ApplicativeError.

    Load default configuration and decode an instance supporting cats.ApplicativeError.

    Example:
    1. 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))))
  13. final def decodeFile[A](file: File)(implicit arg0: Decoder[A]): Either[Error, A]

    Load configuration from file and decode an instance.

    Load configuration from file and decode an instance.

    Example:
    1. 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))))
  14. final def decodeFileAccumulating[A](file: File)(implicit arg0: Decoder[A]): ValidatedNel[Error, A]
  15. final def decodePath[A](config: Config, path: String)(implicit arg0: Decoder[A]): Either[Error, A]

    Decode of an instance at a specific path.

    Decode of an instance at a specific path.

    Example:
    1. 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))
  16. final def decodePath[A](path: String)(implicit arg0: Decoder[A]): Either[Error, A]

    Load the default configuration and decode an instance.

    Load the default configuration and decode an instance.

    Example:
    1. 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))
  17. final def decodePathF[F[_], A](config: Config, path: String)(implicit arg0: Decoder[A], ev: ApplicativeError[F, Throwable]): F[A]

    Decode an instance supporting cats.ApplicativeError at a specific path.

    Decode an instance supporting cats.ApplicativeError at a specific path.

    Example:
    1. 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))
  18. final def decodePathF[F[_], A](path: String)(implicit arg0: Decoder[A], ev: ApplicativeError[F, Throwable]): F[A]

    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.

    Example:
    1. 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))
  19. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  21. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  22. final def finishDecode[A](input: Either[ParsingFailure, Json])(implicit decoder: Decoder[A]): Either[Error, A]
    Attributes
    protected[this]
    Definition Classes
    Parser
  23. final def finishDecodeAccumulating[A](input: Either[ParsingFailure, Json])(implicit decoder: Decoder[A]): ValidatedNel[Error, A]
    Attributes
    protected[this]
    Definition Classes
    Parser
  24. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  25. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  26. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  27. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  28. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  29. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  30. final def parse(input: String): Either[ParsingFailure, Json]
    Definition Classes
    parser → Parser
  31. final def parse(config: Config): Either[ParsingFailure, Json]
  32. final def parse(): Either[ParsingFailure, Json]
  33. final def parseFile(file: File): Either[ParsingFailure, Json]
  34. final def parsePath(config: Config, path: String): Either[ParsingFailure, Json]
  35. final def parsePath(path: String): Either[ParsingFailure, Json]
  36. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  37. def toString(): String
    Definition Classes
    AnyRef → Any
  38. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  39. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  40. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from Parser

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped