typesafe-config-scala


License

License

Categories

Categories

Scala Languages config Application Layer Libs Configuration
GroupId

GroupId

com.github.andyglow
ArtifactId

ArtifactId

typesafe-config-scala_3
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

typesafe-config-scala
typesafe-config-scala
Project URL

Project URL

http://github.com/andyglow/typesafe-config-scala
Project Organization

Project Organization

andyglow
Source Code Management

Source Code Management

https://github.com/andyglow/typesafe-config-scala

Download typesafe-config-scala_3

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.andyglow/typesafe-config-scala_3/ -->
<dependency>
    <groupId>com.github.andyglow</groupId>
    <artifactId>typesafe-config-scala_3</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.andyglow/typesafe-config-scala_3/
implementation 'com.github.andyglow:typesafe-config-scala_3:2.0.0'
// https://jarcasting.com/artifacts/com.github.andyglow/typesafe-config-scala_3/
implementation ("com.github.andyglow:typesafe-config-scala_3:2.0.0")
'com.github.andyglow:typesafe-config-scala_3:jar:2.0.0'
<dependency org="com.github.andyglow" name="typesafe-config-scala_3" rev="2.0.0">
  <artifact name="typesafe-config-scala_3" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.andyglow', module='typesafe-config-scala_3', version='2.0.0')
)
libraryDependencies += "com.github.andyglow" % "typesafe-config-scala_3" % "2.0.0"
[com.github.andyglow/typesafe-config-scala_3 "2.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala3-library_3 jar 3.0.0
com.typesafe : config jar 1.4.1

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_3 jar 3.2.9

Project Modules

There are no modules declared in this project.

Typesafe Config (little scala wrapper)

Build Status codecov mvn

Little scala extension to Typesafe Config

Usage

build.sbt

libraryDependencies += "com.github.andyglow" %% "typesafe-config-scala" % ${LATEST_VERSION} % Compile

Code

Import it

import com.github.andyglow.config._

And then you will be able to

Get value by specifying needed type

val v1 = config.get[String]("path")
val v2 = config.get[Int]("path")
val v3 = config.get[FiniteDuration]("path")

Get rid of if hasPath this else that by leveraging notion of options

// optional value
val val1: Option[String] = config.get[Option[String]]("path")
val val2: String         = config.getOrElse[String]("path", "default")

Have more flexible api for working with multi-values

val list1     = config.get[List[String]]("path")
val set2      = config.get[Set[Int]]("path")
val iterator3 = config.get[Iterator[ConfigMemorySize]]("path")

Supported types

  • String
  • Int
  • Boolean
  • Double
  • Long
  • Bytes (file size, etc...)
  • Duration (java.time)
  • Duration (scala)
  • FiniteDuration
  • ConfigList
  • Config
  • ConfigObject
  • ConfigMemorySize
  • Date (java.util)
  • Date (java.sql)
  • Time (java.sql)
  • Timestamp (java.sql)
  • LocalDate (java.time)
  • LocalTime (java.time)
  • LocalDateTime (java.time)
  • OffsetDateTime (java.time)
  • ZonedDateTime (java.time)
  • DayOfWeek (java.time)
  • Month (java.time)
  • Year (java.time)
  • Option[T] where T is one of the supported types
  • scala collections. Seq[T], etc. Any sort of collection types which has corresponding CanBuildFrom

Extending

Also this can be extended by providing implementations for FromConf and/or ConfType (used for collections and might be implicitly reused for FromConf) For example take a look at com.github.andyglow.config.ConfType#juDateT implementation and spec at com.github.andyglow.config.JavaUtilDateExtSpec

Flatten

Often we need to transform configs into some more trivial structures like Maps or java Properties. For these sort or problems we provide Flatten function. It map take Config or ConfigValue and produce either Properties or Map. Example:

val conf: Config = ???

// for config
val properties = Flatten[java.util.Properties](conf)
val stringMap = Flatten[Map[String, String]](conf)

// for value
val properties = Flatten[java.util.Properties](conf.getValue("some-prop"))
val stringMap = Flatten[Map[String, String]](conf.getValue("some-prop"))

// also you can flatten config into already initialized instance of either Properties of Map
val propertiesWithConfig = Flatten(conf.getValue("some-prop"), properties)
val stringMapWithConfig = Flatten(conf.getValue("some-prop"), stringMap)

Versions

Version
2.0.0