Search code examples
scalaconfigurationconfigconfiguration-fileslift

Specify a list of values for a key in Lift framework config


In scala-lift v2.6, src/main/resources/app/confg/parameters.conf looks very much like a json:

env_type {

  dev {
    greeting = "greeting: dev"

    lift {
      runMode = "development"
    }

    dryRun = true
    etlPrune = false

    testMode = true
  }
}

Is there any way to specify a list of values for a certain key in such config format?


Solution

  • The format is a JSON superset called HOCON ("Human-Optimized Config Object Notation"), which is what the Typesafe Config library uses.

    To specify multiple values for a key, use square brackets and commas. For example:

    env_type {
      dev {
        names = ["dev", "sandbox", "alt-prod"]
      }
    }
    

    To get names in your application code:

    val conf = ConfigFactory.load
    val devNames = conf.getStringList("env_type.dev.names") // java.util.List[String]