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
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))
- Alphabetic
- By Inheritance
- syntax
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- implicit final class CirceConfigOps extends AnyVal
Enriches com.typesafe.config.Config instances with methods to decode to a specific type.
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- 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.
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.
Example: - 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.
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.
Example: - implicit val durationDecoder: Decoder[FiniteDuration]
Decoder for reading duration format.
Decoder for reading duration format.
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)
Example: - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- implicit val memorySizeDecoder: Decoder[ConfigMemorySize]
Decoder for reading size in bytes format into a com.typesafe.config.ConfigMemorySize.
Decoder for reading size in bytes format into a com.typesafe.config.ConfigMemorySize.
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))
Example: - final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- implicit val periodDecoder: Decoder[Period]
Decoder for reading period format.
Decoder for reading period format.
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)
Example: - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()