circe-config

Yet another Typesafe Config decoder

License

License

Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

io.circe
ArtifactId

ArtifactId

circe-config_2.11
Last Version

Last Version

0.7.0-M1
Release Date

Release Date

Type

Type

jar
Description

Description

circe-config
Yet another Typesafe Config decoder
Project URL

Project URL

https://github.com/circe/circe-config
Project Organization

Project Organization

io.circe
Source Code Management

Source Code Management

https://github.com/circe/circe-config

Download circe-config_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/io.circe/circe-config_2.11/ -->
<dependency>
    <groupId>io.circe</groupId>
    <artifactId>circe-config_2.11</artifactId>
    <version>0.7.0-M1</version>
</dependency>
// https://jarcasting.com/artifacts/io.circe/circe-config_2.11/
implementation 'io.circe:circe-config_2.11:0.7.0-M1'
// https://jarcasting.com/artifacts/io.circe/circe-config_2.11/
implementation ("io.circe:circe-config_2.11:0.7.0-M1")
'io.circe:circe-config_2.11:jar:0.7.0-M1'
<dependency org="io.circe" name="circe-config_2.11" rev="0.7.0-M1">
  <artifact name="circe-config_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.circe', module='circe-config_2.11', version='0.7.0-M1')
)
libraryDependencies += "io.circe" % "circe-config_2.11" % "0.7.0-M1"
[io.circe/circe-config_2.11 "0.7.0-M1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
com.typesafe : config jar 1.3.4
io.circe : circe-core_2.11 jar 0.12.0-M3
io.circe : circe-parser_2.11 jar 0.12.0-M3

test (7)

Group / Artifact Type Version
io.circe : circe-generic_2.11 jar 0.12.0-M3
io.circe : circe-testing_2.11 jar 0.12.0-M3
org.typelevel : cats-effect_2.11 jar 2.0.0-M4
org.typelevel : discipline-core_2.11 jar 0.12.0-M3
org.scalacheck : scalacheck_2.11 jar 1.14.0
org.scalatest : scalatest_2.11 jar 3.1.0-SNAP13
org.scalatestplus : scalatestplus-scalacheck_2.11 jar 1.0.0-SNAP8

Project Modules

There are no modules declared in this project.

circe-config

Travis CI Status Latest Version Badge

Small library for translating between HOCON, Java properties, and JSON documents and circe's JSON AST.

At a high-level it can be used as a circe powered front-end for the Typesafe config library to enable boilerplate free loading of settings into Scala types. More generally it provides parsers and printers for interoperating with Typesafe config's JSON AST.

Usage

To use this library configure your sbt project with the following line:

libraryDependencies += "io.circe" %% "circe-config" % "0.7.0"

Documentation

Example

The following examples use io.circe:circe-generic as a dependency to automatically derive decoders. They load the configuration found in application.conf.

scala> import com.typesafe.config.{ ConfigFactory, ConfigMemorySize }
scala> import io.circe.generic.auto._
scala> import io.circe.config.syntax._
scala> import scala.concurrent.duration.FiniteDuration

scala> case class ServerSettings(host: String, port: Int, timeout: FiniteDuration, maxUpload: ConfigMemorySize)
scala> case class HttpSettings(server: ServerSettings, version: Option[Double])
scala> case class AppSettings(http: HttpSettings)

// Load default configuration and decode instances
scala> import io.circe.config.parser

scala> parser.decode[AppSettings]()
res0: Either[io.circe.Error,AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080,5 seconds,ConfigMemorySize(5242880)),Some(1.1))))

scala> parser.decodePath[ServerSettings]("http.server")
res1: Either[io.circe.Error,ServerSettings] = Right(ServerSettings(localhost,8080,5 seconds,ConfigMemorySize(5242880)))

scala> val config = ConfigFactory.load()

// Decode instances from an already loaded configuration

scala> config.as[ServerSettings]("http.server")
res2: Either[io.circe.Error,ServerSettings] = Right(ServerSettings(localhost,8080,5 seconds,ConfigMemorySize(5242880)))

scala> config.as[HttpSettings]("http")
res3: Either[io.circe.Error,HttpSettings] = Right(HttpSettings(ServerSettings(localhost,8080,5 seconds,ConfigMemorySize(5242880)),Some(1.1)))

scala> config.as[AppSettings]
res4: Either[io.circe.Error,AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080,5 seconds,ConfigMemorySize(5242880)),Some(1.1))))

If you are using cats.effect.IO, or some other type F[_] that provides a cats.ApplicativeError, you can use the following:

scala> import cats.effect.IO
scala> import io.circe.generic.auto._
scala> import io.circe.config.parser

scala> case class ServerSettings(host: String, port: Int)
scala> case class HttpSettings(server: ServerSettings, version: Option[Double])
scala> case class AppSettings(http: HttpSettings)

scala> parser.decodeF[IO, AppSettings]()
res0: cats.effect.IO[AppSettings] = IO(AppSettings(HttpSettings(ServerSettings(localhost,8080),Some(1.1))))

scala> val settings: IO[AppSettings] = parser.decodeF[IO, AppSettings]
scala> settings.unsafeRunSync()
res1: AppSettings = AppSettings(HttpSettings(ServerSettings(localhost,8080),Some(1.1)))

scala> parser.decodePathF[IO, ServerSettings]("http.server")
res2: cats.effect.IO[ServerSettings] = IO(ServerSettings(localhost,8080))

scala> parser.decodePathF[IO, ServerSettings]("path.not.found")
res3: cats.effect.IO[ServerSettings] = IO(throw io.circe.ParsingFailure: Path not found in config)

This makes the configuration directly available in your F[_], such as cats.effect.IO, which handles any errors.

Contributing

Contributions are very welcome. Please see instructions on how to create issues and submit patches.

Releasing

To release version x.y.z run:

> sbt -Dproject.version=x.y.z release

License

circe-config is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

io.circe

circe

Versions

Version
0.7.0-M1
0.6.1
0.6.0
0.5.0
0.4.1
0.4.0
0.4.0-M1
0.3.0