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 syntax

Implicits for decoding Typesafe Config values and instances using circe decoders.

In addition to syntax.durationDecoder and syntax.memorySizeDecoder for reading Typesafe Config specific value formats, this module also provides syntax.CirceConfigOps for decoding loaded configurations.

Source
syntax.scala
Example:
  1. scala> import io.circe.generic.auto._
    scala> import io.circe.config.syntax._
    scala> import scala.concurrent.duration.FiniteDuration
    scala> case class ServerSettings(port: Int, host: String, timeout: FiniteDuration)
    scala> val config = com.typesafe.config.ConfigFactory.parseString("port = 7357, host = localhost, timeout = 5 s")
    scala> config.as[ServerSettings]
    res0: Either[io.circe.Error, ServerSettings] = Right(ServerSettings(7357,localhost,5 seconds))
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. syntax
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. implicit final class CirceConfigOps extends AnyVal

    Enriches com.typesafe.config.Config instances with methods to decode to a specific type.

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. implicit val configDecoder: Decoder[Config]

    Decoder for converting io.circe.Json to com.typesafe.config.Config.

    Decoder for converting io.circe.Json to com.typesafe.config.Config.

    Converts a circe JSON object to a Typesafe Config instance.

    Example:
    1. scala> import io.circe.Json
      scala> import com.typesafe.config.Config
      scala> import io.circe.config.syntax._
      
      scala> val hostJson = Json.fromString("localhost")
      scala> val portJson = Json.fromInt(8080)
      scala> val serverJson = Json.obj("host" -> hostJson, "port" -> portJson)
      
      scala> configDecoder.decodeJson(Json.obj("host" -> hostJson))
      res0: io.circe.Decoder.Result[Config] = Right(Config(SimpleConfigObject({"host":"localhost"})))
      scala> serverJson.as[Config]
      res1: io.circe.Decoder.Result[Config] = Right(Config(SimpleConfigObject({"host":"localhost","port":8080})))
      
      scala> portJson.as[Config]
      res2: io.circe.Decoder.Result[Config] = Left(DecodingFailure(JSON must be an object, was type NUMBER, List()))
    See also

    configValueDecoder for decoding any circe JSON AST.

  7. implicit val configValueDecoder: Decoder[ConfigValue]

    Decoder for converting io.circe.Json to com.typesafe.config.ConfigValue.

    Decoder for converting io.circe.Json to com.typesafe.config.ConfigValue.

    Maps any circe JSON AST to the Typesafe Config AST.

    Example:
    1. scala> import io.circe.Json
      scala> import com.typesafe.config.ConfigValue
      scala> import io.circe.config.syntax._
      
      scala> val hostJson = Json.fromString("localhost")
      scala> val portJson = Json.fromInt(8080)
      scala> val serverJson = Json.obj("host" -> hostJson, "port" -> portJson)
      
      scala> configValueDecoder.decodeJson(hostJson)
      res0: io.circe.Decoder.Result[ConfigValue] = Right(Quoted("localhost"))
      
      scala> configValueDecoder.decodeJson(portJson)
      res1: io.circe.Decoder.Result[ConfigValue] = Right(ConfigLong(8080))
      
      scala> serverJson.as[ConfigValue]
      res2: io.circe.Decoder.Result[ConfigValue] = Right(SimpleConfigObject({"host":"localhost","port":8080}))
    See also

    configDecoder for decoding circe JSON objects to a Typesafe Config instance.

  8. implicit val durationDecoder: Decoder[FiniteDuration]

    Decoder for reading duration format.

    Decoder for reading duration format.

    Example:
    1. scala> import io.circe.Json
      scala> import io.circe.config.syntax._
      scala> import scala.concurrent.duration.FiniteDuration
      
      scala> durationDecoder.decodeJson(Json.fromString("5 seconds"))
      res0: io.circe.Decoder.Result[FiniteDuration] = Right(5 seconds)
      scala> durationDecoder.decodeJson(Json.fromString("1 hour"))
      res1: io.circe.Decoder.Result[FiniteDuration] = Right(1 hour)
      
      scala> Json.fromString("200 ms").as[FiniteDuration]
      res2: io.circe.Decoder.Result[FiniteDuration] = Right(200 milliseconds)
  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  12. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. implicit val memorySizeDecoder: Decoder[ConfigMemorySize]

    Decoder for reading size in bytes format into a com.typesafe.config.ConfigMemorySize.

    Example:
    1. scala> import io.circe.Json
      scala> import io.circe.config.syntax._
      scala> import com.typesafe.config.ConfigMemorySize
      
      scala> memorySizeDecoder.decodeJson(Json.fromString("128M"))
      res0: io.circe.Decoder.Result[ConfigMemorySize] = Right(ConfigMemorySize(134217728))
      scala> memorySizeDecoder.decodeJson(Json.fromString("4096 KiB"))
      res1: io.circe.Decoder.Result[ConfigMemorySize] = Right(ConfigMemorySize(4194304))
      
      scala> Json.fromString("32 GB").as[ConfigMemorySize]
      res2: io.circe.Decoder.Result[ConfigMemorySize] = Right(ConfigMemorySize(32000000000))
  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. implicit val periodDecoder: Decoder[Period]

    Decoder for reading period format.

    Decoder for reading period format.

    Example:
    1. scala> import io.circe.Json
      scala> import io.circe.config.syntax._
      scala> import java.time.Period
      
      scala> periodDecoder.decodeJson(Json.fromString("1 day"))
      res0: io.circe.Decoder.Result[Period] = Right(P1D)
      scala> periodDecoder.decodeJson(Json.fromString("3 y"))
      res1: io.circe.Decoder.Result[Period] = Right(P3Y)
      
      scala> Json.fromString("24 months").as[Period]
      res2: io.circe.Decoder.Result[Period] = Right(P24M)
  20. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  21. def toString(): String
    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  24. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped